2 require_once("sesion.php");
3 require_once("../contenido/sub.php");
7 /* Class constructor */
10 /* User submitted login form */
11 if(isset($_POST['sublogin'])){
14 /* User submitted registration form */
15 else if(isset($_POST['subjoin'])){
16 $this->procRegister();
18 /* User submitted forgot password form */
19 else if(isset($_POST['subforgot'])){
20 $this->procForgotPass();
22 /* User submitted edit account form */
23 else if(isset($_POST['subedit'])){
24 $this->procEditAccount();
27 * The only other reason user should be directed here
28 * is if he wants to logout, which means user is
29 * logged in currently.
31 else if($session->logged_in
){
32 DEPURAR ('ok Logout');
36 * Should not get here, which means user is viewing this page
37 * by mistake and therefore is redirected.
40 header("Location: ../");
45 * procLogin - Processes the user submitted login form, if errors
46 * are found, the user is redirected to correct the information,
47 * if not, the user is effectively logged in to the system.
50 global $session, $form;
52 DEPURAR ("Intengo de LOGIN");
53 $retval = $session->login($_POST['codigo'], $_POST['clave'], isset($_POST['remember']));
55 /* Login successful */
57 $_SESSION['regsuccess'] = true;
62 $_SESSION['regsuccess'] = false;
63 $_SESSION['value_array'] = $_POST;
64 $_SESSION['error_array'] = $form->getErrorArray();
66 header("Location:../");
70 * procLogout - Simply attempts to log the user out of the system
71 * given that there is no logout form to process.
73 function procLogout(){
75 $retval = $session->logout();
76 header("Location: ../");
80 * procRegister - Processes the user submitted registration form,
81 * if errors are found, the user is redirected to correct the
82 * information, if not, the user is effectively registered with
83 * the system and an email is (optionally) sent to the newly
86 function procRegister(){
87 global $session, $form;
88 /* Convert username to all lowercase (by option) */
90 $_POST['codigo'] = strtolower($_POST['codigo']);
92 /* Registration attempt */
93 $retval = $session->register($_POST['codigo'], $_POST['clave'], $_POST['nombre'],$_POST['razon'], $_POST['email'], $_POST['telefono1'], $_POST['telefono2'], $_POST['telefono3'], '', $_POST['notas']);
95 /* Registration Successful */
96 $_SESSION['reguname'] = $_POST['codigo'];
98 $_SESSION['regsuccess'] = true;
100 /* Error found with form */
101 else if($retval == 1){
102 $_SESSION['value_array'] = $_POST;
103 $_SESSION['error_array'] = $form->getErrorArray();
104 $_SESSION['regsuccess'] = false;
106 /* Registration attempt failed */
107 else if($retval == 2){
108 $_SESSION['regsuccess'] = false;
111 header("Location: ../?"._ACC_
."=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['codigo'];
123 $field = "user"; //Use field name for username
124 if(!$subuser ||
strlen($subuser = trim($subuser)) == 0){
125 $form->setError($field, "* Username not entered<br>");
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 */
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 */
159 $_SESSION['forgotpass'] = false;
163 header("Location: ../?accion=rpr+clave");
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['newpass'], $_POST['codigo'], $_POST['nombre'],$_POST['razon'], $_POST['email'], $_POST['telefono1'], $_POST['telefono2'], $_POST['telefono3'], '', $_POST['notas']);
176 /* Account edit successful */
178 $_SESSION['useredit'] = true;
180 /* Error found with form */
182 $_SESSION['value_array'] = $_POST;
183 $_SESSION['error_array'] = $form->getErrorArray();
185 header("Location: ../?"._ACC_
."=editar+usuario:".$_POST['codigo']);
189 /* Initialize process */
190 $process = new Process
;