function forgot () { // Load Auth app $auth_app = Frix::app('auth'); // Already authorized? if ($auth_app->get_user()) { // Go to the admin home redir(url(self::$root)); } // Load AuthUser model $auth_app->load_model('AuthUser'); // Get model meta $meta = AuthUser::meta(); $f = new Form; $f->add_fields(array( 'email' => new CharField('E-mail', array('length' => 100)), )); if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Get form data $f->input($_POST); $email = $f->get_email(); // Check for a valid e-mail address. if (!validate_email($email)) { self::$context['msg'] = sprintf('Invalid e-mail address "%s"!', $email); self::$context['msg_type'] = 'err'; } else { // Get user by e-mail address $user = $meta->one(array('email' => $email)); if ($user) { // Create a new password $pass = make_pass(); $msg = 'Your new passord is:' . "\n" . $pass . "\n\n" . 'You can log in using your username:'******'New password', $msg, Frix::app('settings')->get('contact_email'), $user->email); // Error sending the msg? if (!$ok) { self::$context['msg'] = 'Couldn\'t send msg.<br />' . 'Password not changed.' ; self::$context['msg_type'] = 'err'; } // Message sucessfully sent? else { // Change user password and save $user->set_password($pass); $user->save(); // Redirect with a success msg redir('./?sent=1'); } } else { self::$context['msg'] = sprintf('E-mail address "%s" not found!', $email); self::$context['msg_type'] = 'err'; } } } else { if ($_GET['sent']) { self::$context['msg'] = 'The new password was sent!<br />'. 'Please check your inbox.' ; self::$context['msg_type'] = 'ok'; } else { self::$context['msg'] = 'Type your e-mail to get a new password.'; } } self::$context['form'] = $f; $t = new Template('frix/admin/forgot'); echo $t->render(self::$context); }