root/devel/lms/join.php

Revision 1288, 5.1 kB (checked in by rho, 1 year ago)

applied #146, now can modify password length limit with $CFG flag

Signed-off-by: Rolando Espinoza La Fuente <darkrho@gmail.com>

  • Property svn:eol-style set to native
Line 
1 <?php
2 // sign up a user from an lms request.
3
4 require_once(dirname(dirname(__FILE__)).'/includes.php');
5 require_once($CFG->dirroot.'lib/lmslib.php');
6 $showform = false;
7 $u = new StdClass;
8 if (empty($USER->signingup)) {
9     // the POST parameters we expect are:
10     $alias = new StdClass;
11     $alias->installid = optional_param('installid');
12     $alias->username = optional_param('username');
13     $alias->firstname = optional_param('firstname');
14     $alias->lastname = optional_param('lastname');
15     $alias->email = optional_param('email');
16     $signature = optional_param('signature');
17
18     $user = find_lms_user($alias->installid,$alias->username,$signature,'signupconfirmation',$alias->firstname,$alias->lastname,$alias->email);
19     if (is_object($user)) {
20         // they already exist!
21         echo $user;
22         // TODO something
23     } else if ($user != LMS_NO_SUCH_USER) {
24         // we have a validation error probably.
25         echo $user;
26         // TODO something
27     } else {
28         // ok, everything is fine, we need to show them the form.
29         $showform = 1;
30         $u->name = $alias->firstname.' '.$alias->lastname;
31         $u->email = $alias->email;
32         $USER->signingup = true;
33         $USER->alias = $alias;
34     }
35 } else {
36     // process the signup form.
37     $u->username = optional_param('username');
38     $u->password1 = optional_param('password1');
39     $u->password2 = optional_param('password2');
40     $u->email = optional_param('email');
41     $u->name = optional_param('name');
42     $mode = optional_param('mode');
43
44     $messages = array();
45     if ($mode == 'join') {
46         // validate
47         if (!validate_username($u->username)) {
48             $messages[] = __gettext("Error! Your username must contain letters and numbers only, cannot be blank, and must be between 3 and 12 characters in length.");
49         } elseif (!username_is_available(strtolower($u->username))) {
50             $messages[] = __gettext("The username '$username' is already taken by another user. You will need to pick a different one.");
51         }
52
53         if (!validate_password($u->password1, $u->password2)) {
54             $messages[] = __gettext("Error! Invalid password. Your passwords must match and be between 6 and 16 characters in length.");
55         }
56
57         if (empty($u->name)) {
58             $messages[] = __gettext("Error! You must enter your fullname");
59         }
60
61         if (empty($messages)) {
62             // we are good to go!
63             $u->password = md5($u->password1);
64             $ident = insert_record('users',$u);
65         }
66     } elseif ($mode == 'login') {
67         $alias = $USER->alias;
68         if (!authenticate_account($u->username, md5($u->password1))) {
69             $messages[] = __gettext('Error! Your username and password does not match our record.');
70         }
71         $USER->alias = $alias;
72         $ident = $USER->ident;
73     } elseif (!empty($mode)) {
74         $messages[] = __gettext('Fatal Error! Unknown action requested.');
75     }
76
77     if (empty($messages)) {
78         $alias = $USER->alias;
79         $alias->user_id = $ident;
80         insert_record('users_alias',$alias);
81
82         // now look for a community for this installation and add them to it.
83         if (!$comm = get_record_select('users','user_type = ? AND name = ?',array('community',$alias->installid))) {
84             $comm = new StdClass;
85             $comm->name = $alias->installid;
86             $comm->username = $alias->installid;
87             $comm->user_type = 'community';
88             $admin = get_admin();
89             $comm->owner = $admin->ident;
90             $comm->ident = insert_record('users',$comm);
91         }
92         $f = new StdClass;
93         $f->owner = $ident;
94         $f->friend = $comm->ident;
95         insert_record('friends',$f);
96         $f->owner = $comm->ident;
97         $f->friend = $ident;
98         insert_record('friends',$f);
99         
100         unset($USER->signingup);
101         unset($USER->alias);
102         if ($mode == 'join') { // we don't need to do these if the user has already had an account.
103             $_SESSION['messages'][] = __gettext('Your account creation was successful!');
104             // authenticate them.
105             authenticate_account($u->username,$u->password);
106         }
107         redirect($CFG->wwwroot.$u->username);
108     }
109     $showform = true;
110 }
111 if (!empty($showform)) {
112     define("context", "lmsjoin");
113     templates_page_setup();
114     
115     $title = __gettext('Join up');
116     ob_start();
117     require_once($CFG->dirroot.'lms/join.html');
118     $body = ob_get_contents();
119     ob_end_clean();
120
121     $body  = templates_draw( array(
122                                'context' => 'contentholder',
123                                'title' => $title,
124                                'body' => $body
125                                ));
126
127     $title1 = __gettext('Login');
128     ob_start();
129     require_once($CFG->dirroot.'lms/login.html');
130     $body1 = ob_get_contents();
131     ob_end_clean();
132
133     $body .= templates_draw( array(
134                                'context' => 'contentholder',
135                                'title' => $title1,
136                                'body' => $body1
137                                ));
138
139     echo templates_page_draw(array($title, $body, '&nbsp;'));
140 }
141
142 ?>
Note: See TracBrowser for help on using the browser.