Test de ecualidad de claves en instalador.
[CLab.git] / process.php
blobe39963a826119e434a51ac6d049817a294f170dd
1 <?
2 /**
3 * Process.php
4 */
5 include("include/session.php");
7 class Process
9 /* Class constructor */
10 function Process(){
11 global $session;
12 /* User submitted login form */
13 if(isset($_POST['sublogin'])){
14 $this->procLogin();
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();
28 /**
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){
34 $this->procLogout();
36 /**
37 * Should not get here, which means user is viewing this page
38 * by mistake and therefore is redirected.
40 else{
41 header("Location: ".$session->referrer);
45 /**
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.
50 function procLogin(){
51 global $session, $form;
52 /* Login attempt */
53 $retval = $session->login($_POST['user'], $_POST['pass'], isset($_POST['remember']));
55 /* Login successful */
56 if($retval){
57 $_SESSION['regsuccess'] = true;
59 /* Login failed */
60 else{
61 $_SESSION['regsuccess'] = false;
62 $_SESSION['value_array'] = $_POST;
63 $_SESSION['error_array'] = $form->getErrorArray();
65 header("Location:./?x=ingresar");
68 /**
69 * procLogout - Simply attempts to log the user out of the system
70 * given that there is no logout form to process.
72 function procLogout(){
73 global $session;
74 $retval = $session->logout();
75 header("Location: ".$session->referrer);
78 /**
79 * procRegister - Processes the user submitted registration form,
80 * if errors are found, the user is redirected to correct the
81 * information, if not, the user is effectively registered with
82 * the system and an email is (optionally) sent to the newly
83 * created user.
85 function procRegister(){
86 global $session, $form;
87 /* Convert username to all lowercase (by option) */
88 if(ALL_LOWERCASE){
89 $_POST['user'] = strtolower($_POST['user']);
91 /* Registration attempt */
92 $retval = $session->register($_POST['user'], $_POST['pass'], $_POST['email'],$_POST['nombre'], $_POST['encargado'], $_POST['catedratico'], $_POST['tipo'], $_POST['departamento']);
94 /* Registration Successful */
95 if($retval == 0){
96 $_SESSION['regsuccess'] = true;
97 $_SESSION['reguname'] = $_POST['user'];
99 /* Error found with form */
100 else if($retval == 1){
101 $_SESSION['value_array'] = $_POST;
102 $_SESSION['error_array'] = $form->getErrorArray();
104 /* Registration attempt failed */
105 else if($retval == 2){
106 $_SESSION['reguname'] = $_POST['user'];
107 $_SESSION['regsuccess'] = false;
110 $_SESSION['post-post'] = true;
111 header("Location: ./?x=registro");
115 * procForgotPass - Validates the given username then if
116 * everything is fine, a new password is generated and
117 * emailed to the address the user gave on sign up.
119 function procForgotPass(){
120 global $database, $session, $mailer, $form;
121 /* Username error checking */
122 $subuser = $_POST['user'];
123 $field = "user"; //Use field name for username
124 if(!$subuser || strlen($subuser = trim($subuser)) == 0){
125 $form->setError($field, "* Username not entered<br>");
127 else{
128 /* Make sure username is in database */
129 $subuser = stripslashes($subuser);
130 if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
131 !eregi("^([0-9a-z])+$", $subuser) ||
132 (!$database->usernameTaken($subuser))){
133 $form->setError($field, "* Username does not exist<br>");
137 /* Errors exist, have user correct them */
138 if($form->num_errors > 0){
139 $_SESSION['value_array'] = $_POST;
140 $_SESSION['error_array'] = $form->getErrorArray();
142 /* Generate new password and email it to user */
143 else{
144 /* Generate new password */
145 $newpass = $session->generateRandStr(8);
147 /* Get email of user */
148 $usrinf = $database->getUserInfo($subuser);
149 $email = $usrinf['email'];
151 /* Attempt to send the email with new password */
152 if($mailer->sendNewPass($subuser,$email,$newpass)){
153 /* Email sent, update database */
154 $database->updateUserField($subuser, "password", md5($newpass));
155 $_SESSION['forgotpass'] = true;
157 /* Email failure, do not change password */
158 else{
159 $_SESSION['forgotpass'] = false;
163 header("Location: ".$session->referrer);
167 * procEditAccount - Attempts to edit the user's account
168 * information, including the password, which must be verified
169 * before a change is made.
171 function procEditAccount(){
172 global $session, $form;
173 /* Account edit attempt */
174 $retval = $session->editAccount($_POST['curpass'], $_POST['newpass'], $_POST['email']);
176 /* Account edit successful */
177 if($retval){
178 $_SESSION['useredit'] = true;
179 header("Location: ".$session->referrer);
181 /* Error found with form */
182 else{
183 $_SESSION['value_array'] = $_POST;
184 $_SESSION['error_array'] = $form->getErrorArray();
185 header("Location: ".$session->referrer);
190 /* Initialize process */
191 $process = new Process;