Exemplo n.º 1
0
 public function create(Request $request)
 {
     $error = Constants::MSG_OK_CODE;
     $messages = [];
     //rules to apply of each field
     $rulesUser = array('name' => 'string|required', 'rank' => 'integer|required|min:0', 'email' => 'email|required', 'password' => 'string|required|min:4|max:32');
     $validatorUser = Validator::make($request->all(), $rulesUser);
     if ($validatorUser->fails()) {
         foreach ($validatorUser->messages()->getMessages() as $key => $value) {
             $messages[] = Lang::get('validator.global', ["name" => $key]);
         }
         $error = Constants::MSG_ERROR_CODE;
     } else {
         $name = $request->input('name');
         $rank = $request->input('rank');
         $email = $request->input('email');
         $password = $request->input('password');
         $user = User::where('email', '=', $email)->first();
         if ($user) {
             $messages[] = Lang::get('users.alreadyExist');
             $error = Constants::MSG_ERROR_CODE;
         } else {
             $password = AccountServiceProvider::hash($email, $password);
             $user = new User();
             $user->name = $name;
             $user->rank = $rank;
             $user->email = $email;
             $user->sha1_password = $password;
             $user->active = Constants::ACTIVE;
             $user->save();
             $messages[] = Lang::get('users.createOk', ["username" => $email]);
         }
     }
     return redirect()->route('users::viewAll')->with(['messages' => $messages, 'error' => $error]);
 }
 public function hashPassword($username, $password)
 {
     return AccountServiceProvider::hash($username, $password);
 }