public function action_view($user_id = null) { if (empty($user_id)) { $user_id = $this->user->id; } try { $this->include_client_scripts('jquery_forms'); $this->template->content = \View::forge('member/account'); $this->template->content->user = $this->user->id == $user_id ? $this->user : \Warden\Model_User::authenticate($user_id, true); if (!$this->template->content->user) { \Session::set_flash('error', "User '{$user_id}' wasn't found in our system."); \Response::redirect('/welcome/404'); } $this->template->content->editable = $this->user->id == $user_id && \Access::can('edit_own_account', $this->user) || \Access::can('edit_any_account', $this->user); $this->template->content->can_unlock = $this->template->content->user->is_access_locked() && \Access::can('unlock_any_user', $this->user); $this->template->content->title = $this->user->id == $user_id ? 'My Account' : $this->template->content->user->username; $this->template->title = $this->template->content->title; if (\Access::can('assign_roles', $this->user)) { $result = \Warden\Model_Role::find('all'); $this->template->content->roles = array(); foreach ($result as $row) { $this->template->content->roles[$row['id']] = $row['name']; } } } catch (Exception $e) { \Session::set_flash('error', $e->getMessage()); \Response::redirect('/welcome/404'); } }
public function action_forgot_password() { if ($this->user) { Response::redirect('/welcome/404'); //page not found } else { $this->template->title = 'User » Forgot Password'; $this->template->content = View::forge('user/forgot_password'); $this->template->content->validation = Validation::forge(); Package::load('captcha'); $this->template->content->captcha = Captcha::forge('simplecaptcha'); $this->include_client_scripts('jquery_forms'); $post = Input::post(); if (!empty($post)) { //add server-side validation $captcha = $this->template->content->captcha; $validation = $this->template->content->validation; $validation->add_field('username_or_email', 'Username or Email', 'required'); $validation->add('captcha', 'Captcha')->add_rule('required')->add_rule(array('captcha' => function ($val, $captcha) { return $captcha->check(); }), $captcha); if ($validation->run()) { try { $user = \Warden\Model_User::authenticate($validation->validated('username_or_email'), true); if ($user) { $user->send_reset_password_instructions(); Session::set_flash('success', 'An email was sent to you with instructions to reset your password.'); } else { Session::set_flash('error', 'Invalid username/email entered. Account does not exist.'); } } catch (Warden\Failure $failure) { Session::set_flash('error', $failure->getMessage()); } catch (Exception $ex) { Session::set_flash('error', $ex->getMessage()); } } else { Session::set_flash('error', 'Invalid username/email entered.'); } } } }