public function put_update($user_id) { if (!ctype_digit($user_id)) { $this->data['message'] = Lang::line('Invalid id to edit user')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::to(ADM_URI . '/users')->with($this->data); } $edit_user = Users\Model\User::find($user_id); if (!isset($edit_user) or empty($edit_user)) { $this->data['message'] = Lang::line('Sorry can\'t find user to update')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::to(ADM_URI . '/users')->with($this->data); } $messages = array('valid_uuid' => Lang::line('Invalid UUID.')->get(ADM_LANG), 'unique_avatar_name' => Lang::line('This combination of avatar first name and avatar last name is already in use')->get(ADM_LANG)); Validator::register('valid_uuid', function ($attribute, $value, $parameters) { return (bool) preg_match('#^[a-z0-9]{8}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{12}$#', $value); }); Validator::register('unique_avatar_name', function ($attribute, $input_value) { $user = Users\Model\User::where('uuid', '!=', Input::get('uuid'))->where(function ($query) use($attribute, $input_value) { $query->where($attribute, '=', $input_value); $query->where('avatar_first_name', '=', Input::get('avatar_first_name')); })->first(); if (!isset($user) or empty($user)) { return true; } return false; }); $rules = array('uuid' => 'required|min:3|max:50|valid_uuid|unique:users,uuid,' . $edit_user->id, 'username' => 'required|min:3|max:50|alpha_dash|unique:users,username,' . $edit_user->id, 'avatar_first_name' => 'required|min:3|max:50', 'avatar_last_name' => 'required|min:3|max:50|unique_avatar_name', 'email' => 'required|email|unique:users,email,' . $edit_user->id, 'status' => 'required', 'password' => 'min:8'); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->passes()) { $group_id = Input::get('group_id'); if (!isset($group_id) or empty($group_id)) { $group_id = 0; } $password = Input::get('password'); if (isset($password) and !empty($password)) { $password = Users\Helper::hash_password(Input::get('password')); $edit_user->password = Hash::make(Input::get('password')); $edit_user->hash = $password['hash']; $edit_user->salt = $password['salt']; } $edit_user->uuid = Input::get('uuid'); $edit_user->username = Input::get('username'); // Disable change of avatar name for now // //$edit_user->avatar_first_name = Input::get('avatar_first_name'); //$edit_user->avatar_last_name = Input::get('avatar_last_name'); $edit_user->email = Input::get('email'); $edit_user->status = Input::get('status'); $edit_user->group_id = $group_id; $edit_user->save(); Event::fire('users.updated', array($edit_user)); $this->data['message'] = __('users::lang.User information was successfully updated', array('avatar_name' => Input::get('avatar_first_name') . ' ' . Input::get('avatar_last_name')))->get(ADM_LANG); $this->data['message_type'] = 'success'; return Redirect::to(ADM_URI . '/users')->with($this->data); } else { return Redirect::to(ADM_URI . '/users/' . $edit_user->id . '/edit')->with_errors($validation)->with_input(); } }
public function delete_destroy($group_id) { if (!ctype_digit($group_id)) { $this->data['message'] = __('groups::lang.Invalid id')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::back()->with($this->data); } if (Bundle::exists('permissions')) { $group = Groups\Model\Group::with('permissions')->find($group_id); } else { $group = Groups\Model\Group::find($group_id); } if (!isset($group) or empty($group)) { $this->data['message'] = __('groups::lang.Sorry cannot find group to delete')->get(ADM_LANG); $this->data['message_type'] = 'error'; return Redirect::back()->with($this->data); } $users_group = Groups\Model\Group::where('slug', '=', 'users')->first(); // if there is users on this group // set all users back to users group if (isset($users_group) and isset($users_group->id)) { $update = Users\Model\User::where('group_id', '=', $group->id)->update(array('group_id' => $users_group->id)); } if (isset($group->permissions) and !empty($group->permissions)) { $group->permissions()->delete(); } $group->delete(); Event::fire('mwi.group_deleted', array($group)); $this->data['message'] = __('groups::lang.Group was successfully destroyed')->get(ADM_LANG); $this->data['message_type'] = 'success'; return Redirect::to(ADM_URI . '/groups')->with($this->data); }
public function post_pwreset() { $rules = array('email' => 'required|email|account_exists'); $messages = array('account_exists' => Lang::line('registration::lang.This email was not found.')->get(APP_LANG)); $account = null; Validator::register('account_exists', function ($attribute, $value, $parameters) use(&$account) { $account = Users\Model\User::where('email', '=', Input::get('email'))->first(); if (isset($account) and !empty($account)) { return true; } return false; }); $validation = Validator::make(Input::all(), $rules, $messages); if ($validation->passes()) { $pwreset_record = new Registration\Model\Code(); $pwreset_record->user_id = $account->id; $pwreset_record->code = Mwi_Core::keygen(); $pwreset_record->save(); // send password reset email // new xblade to parse the email template $xblade = new Xblade(); $xblade->scopeGlue(':'); // data to be passed to email template $data['user'] = $account; $data['forgotten_password_code'] = $pwreset_record->code; $data['url']['base'] = URL::base(); $data['settings']['site_name'] = Config::get('settings::core.site_name'); $data['request']['ip'] = Request::ip(); $data['request']['user_agent'] = implode(', ', Request::header('user-agent')); $data['request']['languages'] = implode(', ', Request::languages()); // get email template based on settings $email_address = Config::get('settings::core.server_email'); $template_id = Config::get('settings::core.registration_pwreset_email_template'); $email_data = Email\Model\Template::find($template_id); // send email to user Email\Message::to($account->email)->from($email_address)->subject($xblade->parse($email_data->subject, $data))->body($xblade->parse($email_data->body, $data))->html($email_data->type)->send(); $this->data['message'] = __('registration::lang.An email was sent to you with instructions to reset your password')->get(APP_LANG); $this->data['message_type'] = 'success'; return Redirect::to('page/home')->with($this->data); } return Redirect::back()->with_errors($validation)->with_input(); }