Hello,

finally i wrote what i want : a simple ldap search page.

i used the login widget as a model.

My main widget is a composite widget of :
 - 1 ldap-search widget
 - 1 datalist widget

One point not obvious for me : when i get data from ldap server, how can i 
pass them to the datalist widget ?
I used a memory store to do this. Is it the right way ?

There is some fog between me and weblocks :)
This first success is like a light in the dark :)

No more words, the code

Project Name : info-utilisateur

##########################
# File conf/store.lisp
##########################
(in-package :info-utilisateur)

(defstore *ldap-results-store* :memory)

##########################
# File src/init-session.lisp
##########################
 (in-package :info-utilisateur)

;; Define callback function to initialize new sessions
(defun init-user-session (root)
  (clean-ldap-results-store)
  (setf (composite-widgets root)
        (make-main-page)))

##########################
# File src/layout.lisp
##########################
(in-package :info-utilisateur)

(defun make-main-page ()
 (make-instance 'composite :widgets
 (list
  (make-instance 'ldap-search-widget)
  (make-instance 'datalist
 :name 'ldap-people
                                 :data-class 'ldap-people
                                 :item-data-view 'ldap-people-data-view))))

##########################
# File src/model/people.lisp
##########################

(in-package :info-utilisateur)

(defclass ldap-people ()
  ((id :accessor ldap-people-id)
   (name :accessor ldap-people-name
 :initarg :name
 :type string)
   (email :accessor ldap-people-email
   :initarg :email
   :type string)))

;;; Data View
(defview ldap-people-data-view (:type data :inherit-from '(:scaffold 
ldap-people))
  (id :hidep t)
  (name :label "Identité"))

##########################
# File src/widget/ldap-search.lisp
##########################
(in-package :info-utilisateur)

(defview ldap-search-view (:type form :persistp nil
                             :buttons '((:submit . "Rechercher"))
                             :caption "Rechercher dans l'annuaire"
                             :focusp t)
  (name :requiredp t :required-indicator nil :label "Nom ou prénom"))

(defun clean-ldap-results-store ()
  (dolist
      (obj (find-persistent-objects *ldap-results-store* 'ldap-people))
    (delete-persistent-object *ldap-results-store* obj)))
 

(defwidget ldap-search-widget ()
  ((view :accessor ldap-s-view
         :initform 'ldap-search-view
         :initarg :view)
   (quickform :accessor ldap-quickform
      :initform nil
      :initarg :quickform)))))

(defmethod render-widget-body ((obj ldap-search-widget) &rest args)
  (declare (ignore args))
   (render-widget (ldap-quickform obj)))

(defmethod initialize-instance :after ((obj ldap-search-widget) &rest 
initargs &key &allow-other-keys)
  (declare (ignore initargs))
  (setf (ldap-quickform obj)
        (make-quickform (ldap-s-view obj)
                        :on-success (lambda (w o)
      (declare (ignore w))
      (clean-ldap-results-store)
      (search-people (slot-value o 'name))
      (mark-dirty (widget-parent obj))
                                      (answer obj)))))
(defun search-people (byname)
  (let ((ldap-conn (ldap:new-ldap :host *ldap-server*
                                  :base *ldap-base*)))
    (when (ldap:bind ldap-conn)
      (let (
            (filter (concatenate 'string
                                 "(&(objectClass=person)(displayName=*"
                                 byname
                                 "*))")))
        (ldap:dosearch (usr (ldap:search ldap-conn filter))
  (persist-object *ldap-results-store*
  (make-instance 'ldap-people
 :name (car (ldap:attr-value usr :displayname))
 :email (car (ldap:attr-value usr :mail)))))))))


Advices are welcome.

Thanks.

Regards.



Post code or a github gist for better guidance.
>

-- 
You received this message because you are subscribed to the Google Groups 
"weblocks" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/weblocks/-/snpVnlV7n5wJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/weblocks?hl=en.

Reply via email to