Example #1
0
 public function post_update_username()
 {
     $val = Validation::forge();
     $val->add_callable('MyRules');
     $val->add_field('username', Lang::get('label.username'), 'required|valid_username|min_length[6]|max_length[50]|unique_username');
     if ($val->run()) {
         $props = array('username' => $val->validated('username'));
         if (Model_Base_User::update($this->user_id, $props)) {
             Auth::force_login($this->user_id);
             $this->data['success'] = Lang::get($this->controller . '.' . $this->action . '.success');
         } else {
             $this->data['error'] = Lang::get($this->controller . '.' . $this->action . '.error');
         }
     } else {
         $this->data['errors'] = $val->error_message();
     }
     return $this->response($this->data);
 }