예제 #1
0
 public function setPreference($attr, $value)
 {
     $user_p = UserPreferences::findOne(['user_id' => $this->id]);
     if (!$user_p) {
         $user_p = new UserPreferences();
         $user_p->user_id = $this->id;
     }
     $user_p->{$attr} = $value;
     return $user_p->save();
 }
예제 #2
0
 /**
  * Create a new account instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 protected function create(array $data)
 {
     do {
         $apiKey = str_random(Helpers::API_KEY_LENGTH);
     } while (User::whereApikey($apiKey)->first());
     do {
         $confirmationCode = str_random(32);
     } while (User::whereConfirmationCode($confirmationCode)->first());
     $firstUser = DB::table('users')->count() == 0;
     $confirmed = $firstUser || !config('upste.require_email_verification');
     $enabled = $firstUser || !config('upste.require_user_approval');
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'apikey' => $apiKey, 'password' => Hash::make($data['password'], ['rounds' => config('upste.password_hash_rounds')]), 'confirmed' => $confirmed, 'confirmation_code' => $confirmed ? null : $confirmationCode, 'admin' => $firstUser, 'enabled' => $enabled]);
     UserPreferences::create(['user_id' => $user->id]);
     return $user;
 }