示例#1
0
 /**
  * Cadastra o usuário.
  *
  * @param Request $request
  * @return array
  */
 public function postRegister(Request $request)
 {
     if (!$request->has(['name', 'email', 'password', 'password_confirmation'])) {
         return ['status' => 'empty_fields'];
     }
     if (!hash_equals(strval($request->input('password')), strval($request->input('password_confirmation')))) {
         return ['status' => 'passwords_do_not_match'];
     }
     if (!filter_var($request->input('email'), FILTER_VALIDATE_EMAIL)) {
         return ['status' => 'invalid_email'];
     }
     if (User::where('email', '=', $request->input('email'))->first()) {
         return ['status' => 'email_exists'];
     }
     $user = User::create(['name' => $request->input('name'), 'email' => $request->input('email'), 'password' => bcrypt(strval($request->input('password')))]);
     AuthToken::create(['user_id' => $user->id, 'token' => $token = md5(str_random() . '_register_token')]);
     return ['status' => 'ok', 'token' => $token, 'user' => $user->toArray()];
 }
示例#2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }