Avail feature updated
[ninja.git] / application / controllers / change_password.php
blob6610a5eb9fb52a3dc8fcbebe716a6db03d66962c
1 <?php defined('SYSPATH') OR die('No direct access allowed.');
2 /**
3 * Password change controller
5 * op5, and the op5 logo are trademarks, servicemarks, registered servicemarks
6 * or registered trademarks of op5 AB.
7 * All other trademarks, servicemarks, registered trademarks, and registered
8 * servicemarks mentioned herein may be the property of their respective owner(s).
9 * The information contained herein is provided AS IS with NO WARRANTY OF ANY
10 * KIND, INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY, AND FITNESS FOR A
11 * PARTICULAR PURPOSE.
13 class Change_Password_Controller extends Authenticated_Controller {
15 public $model = false;
17 public function __construct()
19 parent::__construct();
21 $this->template->content = $this->add_view('change_password/change_password');
22 $this->template->disable_refresh = true;
23 $this->template->title = _('Configuration ยป Change password');
25 $this->template->toolbar = new Toolbar_Controller( _("My Account"), _("Change Password") );
26 $root = url::base(FALSE) . 'index.php/';
28 $this->template->toolbar->info(
29 '<a href="' . $root . 'user" title="' . _( "Account Settings" ) . '">' . _( "Account Settings" ) . '</a>'
32 if ( Auth::instance()->authorized_for('access_rights') ) {
33 $this->template->toolbar->info(
34 '<a href="' . $root . 'user/menu_edit' . '" title="' . _( "Edit user menu" ) . '">' . _( "Edit user menu" ) . '</a>'
40 public function index()
42 $this->template->content->status_msg = '';
45 public function change_password()
48 $messages = array(
49 "TO_SHORT" => _('The password must be at least 5 characters long.'),
50 "NO_UPDATE" => _('Authentication backend reported that password could not be updated.'),
51 "INVALID_CURRENT" => _('You entered incorrect current password.'),
52 "NO_MATCH" => _('New password did not match repeated password.'),
53 "SUCCESS" => _('Password changed successfully')
56 $post = Validation::factory( $_POST );
57 $post->add_rules( '*', 'required' );
59 $current_password = $this->input->post('current_password', false);
60 $new_password = $this->input->post('new_password', false);
61 $new_password2 = $this->input->post('confirm_password', false);
63 if ( strlen( $new_password ) < 5 || strlen( $new_password2 ) < 5 ) {
65 $this->template->content->status_msg = $messages[ "TO_SHORT" ];
67 } elseif ( $new_password == $new_password2 ) {
69 $auth = Auth::instance();
70 $user = $auth->get_user();
72 if ( $auth->verify_password( $user, $current_password ) ) {
74 if ( $auth->update_password($user, $new_password) ) {
75 $this->template->content->successful = true;
76 $this->template->content->status_msg = $messages[ "SUCCESS" ];
77 } else {
78 $this->template->content->status_msg = $messages[ "NO_UPDATE" ];
81 } else {
82 $this->template->content->status_msg = $messages[ "INVALID_CURRENT" ];
85 } else {
86 $this->template->content->status_msg = $messages[ "NO_MATCH" ];