function edit(ProfileRequest $request)
 {
     $input = $request->all();
     $user = Auth::user();
     if ($input['type'] == 'account') {
         $user->name = $input['name'];
         $user->email = $input['email'];
         $user->save();
     } elseif ($input['type'] == 'password') {
         $user->password = bcrypt($input['new_password']);
         $user->save();
     } elseif ($input['type'] == 'data') {
         // Remove empty inputs
         $input = array_filter($input);
         // Create new row in user data if none exists
         if (is_null($user->data)) {
             $data = new UserData();
             $data->user_id = $user->id;
             $data->save();
             $data->update($input);
         } else {
             $user->data->update($input);
         }
     }
     $request->session()->flash('success', 'Your profile was updated.');
     return redirect('/profile');
 }
 public function updateSelf(UserRequest $request)
 {
     $user = Auth::user();
     $input = $request->all();
     if ($input['type'] == 'data') {
         // Remove empty inputs
         $input = array_filter($input);
         // Create new row in user data if none exists
         if (is_null($user->data)) {
             $data = new UserData();
             $data->user_id = $user->id;
             $data->save();
             $data->update($input);
         } else {
             $user->data->update($input);
         }
     }
     $request->session()->flash('success', 'Your profile was updated.');
     return redirect('/');
 }
Beispiel #3
0
 public static function saveSocial(User $model, UserData $user_data)
 {
     $model->{$user_data->getObjectName()} = $user_data->id;
     $model->save();
     $user_data->save();
 }
 public function social(ClientInterface $client)
 {
     $user_data = new UserData($client->getName(), $client->getUserAttributes());
     if (Yii::$app->user->isGuest) {
         $user = User::findSocial($user_data->getObjectName(), $user_data->getObjectName());
         if ($user) {
             Login::login($user);
         } else {
             $user_data->save();
         }
     } else {
         User::saveSocial(Yii::$app->user->identity, $user_data);
     }
     Yii::$app->session->set('social', $client->getName());
 }
Beispiel #5
0
 /**
  * @param $name
  * @param $data
  */
 protected static function updateRecord($name, $data)
 {
     $rec = static::findRecord($name);
     if (!$rec) {
         $rec = new UserData();
         $rec->user_id = Yii::$app->user->getId();
         $rec->name = $name;
     }
     $rec->data = $data;
     $rec->save();
     static::$_records[$name] = $rec;
 }