5 include("include/session.php");
9 /* Class constructor */
12 /* User submitted login form */
13 if(isset($_POST['sublogin'])){
16 /* User submitted registration form */
17 else if(isset($_POST['subjoin'])){
18 $this->procRegister();
20 /* User submitted forgot password form */
21 else if(isset($_POST['subforgot'])){
22 $this->procForgotPass();
24 /* User submitted edit account form */
25 else if(isset($_POST['subedit'])){
26 $this->procEditAccount();
29 * The only other reason user should be directed here
30 * is if he wants to logout, which means user is
31 * logged in currently.
33 else if($session->logged_in
){
37 * Should not get here, which means user is viewing this page
38 * by mistake and therefore is redirected.
41 header("Location: ".$session->referrer
);
46 * procLogin - Processes the user submitted login form, if errors
47 * are found, the user is redirected to correct the information,
48 * if not, the user is effectively logged in to the system.
51 global $session, $form;
53 $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
55 /* Login successful */
57 $_SESSION['regsuccess'] = true;
58 unset($_SESSION['regfail']);
62 $_SESSION['regsuccess'] = false;
63 $_SESSION['regfail'] = true;
64 $_SESSION['value_array'] = $_POST;
65 $_SESSION['error_array'] = $form->getErrorArray();
67 header("Location:./?x=ingresar");
71 * procLogout - Simply attempts to log the user out of the system
72 * given that there is no logout form to process.
74 function procLogout(){
76 $retval = $session->logout();
77 header("Location: ".$session->referrer
);
81 * procRegister - Processes the user submitted registration form,
82 * if errors are found, the user is redirected to correct the
83 * information, if not, the user is effectively registered with
84 * the system and an email is (optionally) sent to the newly
87 function procRegister(){
88 global $session, $form;
89 /* Convert username to all lowercase (by option) */
91 $_POST['user'] = strtolower($_POST['user']);
93 /* Registration attempt */
94 $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'],$_POST['nombre'], $_POST['encargado'], $_POST['catedratico'], $_POST['tipo'], $_POST['departamento']);
96 /* Registration Successful */
98 $_SESSION['regsuccess'] = true;
99 $_SESSION['reguname'] = $_POST['user'];
101 /* Error found with form */
102 else if($retval == 1){
103 $_SESSION['value_array'] = $_POST;
104 $_SESSION['error_array'] = $form->getErrorArray();
106 /* Registration attempt failed */
107 else if($retval == 2){
108 $_SESSION['reguname'] = $_POST['user'];
109 $_SESSION['regsuccess'] = false;
112 header("Location: ./?x=registro");
116 * procForgotPass - Validates the given username then if
117 * everything is fine, a new password is generated and
118 * emailed to the address the user gave on sign up.
120 function procForgotPass(){
121 global $database, $session, $mailer, $form;
122 /* Username error checking */
123 $subuser = $_POST['user'];
124 $field = "user"; //Use field name for username
125 if(!$subuser ||
strlen($subuser = trim($subuser)) == 0){
126 $form->setError($field, "* Username not entered<br>");
129 /* Make sure username is in database */
130 $subuser = stripslashes($subuser);
131 if(strlen($subuser) < 5 ||
strlen($subuser) > 30 ||
132 !eregi("^([0-9a-z])+$", $subuser) ||
133 (!$database->usernameTaken($subuser))){
134 $form->setError($field, "* Username does not exist<br>");
138 /* Errors exist, have user correct them */
139 if($form->num_errors
> 0){
140 $_SESSION['value_array'] = $_POST;
141 $_SESSION['error_array'] = $form->getErrorArray();
143 /* Generate new password and email it to user */
145 /* Generate new password */
146 $newpass = $session->generateRandStr(8);
148 /* Get email of user */
149 $usrinf = $database->getUserInfo($subuser);
150 $email = $usrinf['email'];
152 /* Attempt to send the email with new password */
153 if($mailer->sendNewPass($subuser,$email,$newpass)){
154 /* Email sent, update database */
155 $database->updateUserField($subuser, "password", md5($newpass));
156 $_SESSION['forgotpass'] = true;
158 /* Email failure, do not change password */
160 $_SESSION['forgotpass'] = false;
164 header("Location: ".$session->referrer
);
168 * procEditAccount - Attempts to edit the user's account
169 * information, including the password, which must be verified
170 * before a change is made.
172 function procEditAccount(){
173 global $session, $form;
174 /* Account edit attempt */
175 $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
177 /* Account edit successful */
179 $_SESSION['useredit'] = true;
180 header("Location: ".$session->referrer
);
182 /* Error found with form */
184 $_SESSION['value_array'] = $_POST;
185 $_SESSION['error_array'] = $form->getErrorArray();
186 header("Location: ".$session->referrer
);
191 /* Initialize process */
192 $process = new Process
;