public function deleteProfile($profile) { $id = $profile->id; if (!$profile->delete()) { return false; } $profile = UserProfile::find($id); return empty($profile); }
public function storeProfile() { if (Auth::check()) { $validation = Validator::make(Input::all(), UserProfile::$rules); if ($validation->fails()) { return Redirect::Back()->withInput()->withErrors($validation); } $profile = UserProfile::find(Auth::User()->id); $profile->first_name = Input::get('first_name'); $profile->last_name = Input::get('last_name'); $profile->save(); return Redirect::to("user/{$profile->id}"); } else { return Redirect::to('login_index'); } }
public function save() { if ($this->validate()) { $changed = false; if ($this->is_new) { $this->password = $this->hashPassword($this->password); $this->password_confirmation = $this->password; $this->activation_code = md5(time() . $this->nickname . $this->email . rand(10000, 99999)); $this->cookie = md5(time() . $this->nickname . $this->email . $this->activation_code . rand(10000, 99999)); $this->version = 1; $changed = true; } else { if ($this->changed_password) { $this->password = $this->hashPassword($this->password); $this->password_confirmation = $this->password; } if (!$this->cookie) { $this->cookie = md5(time() . $this->nickname . $this->email . $this->activation_code . rand(10000, 99999)); } // Update version if ($this->calculateHash() != $this->hash) { $this->version++; $changed = true; } } if ($this->activated && !$this->affiliate_code) { $this->affiliate_code = uniqid(); } $result = parent::save(self::table); if ($result) { if ($changed) { Website::triggerAll($this); } $this->sync_forums(); if ($this->activated and $this->allow_emails) { $this->newzapp_signup(); } $id = mysql_real_escape_string($this->id); $user_profile = UserProfile::find("user_profiles.user_id = '{$id}'"); if (!$user_profile) { // Create a profile for the user $user_profile = new UserProfile(); $user_profile->user_id = $this->id; $user_profile->save(); } } return $result; } else { return false; } }
public function updateMyDetails($userId, $data) { try { $user = \User::find($userId); $user->first_name = $data['first_name']; $user->last_name = $data['last_name']; $user->save(); $userProfile = \UserProfile::find($userId); $userProfile->facebook = $data['facebook']; $userProfile->twitter = $data['twitter']; $userProfile->googleplus = $data['googleplus']; $userProfile->about = $data['about']; $userProfile->website = $data['website']; $userProfile->phone = $data['phone']; $userProfile->save(); $userProfile = \File::delete(public_path() . '/images/profilepics/' . $userId . '.png'); $imageResult = \App::make('AuthController')->{'createUserImage'}($user->id, $data['first_name'][0], $data['last_name'][0]); return 'success'; } catch (\Exception $e) { \Log::error('Something Went Wrong in User Repository - updateMyDetails():' . $e->getMessage()); return 'error'; } }
/** * Update the specified resource in storage. * * @param $user * @return Response */ public function putEdit($user) { if (!Input::get('password')) { $rules = array('displayname' => 'required', 'email' => 'required|email', 'password' => 'min:4|confirmed', 'password_confirmation' => 'min:4'); } else { $rules = array('displayname' => 'required', 'email' => 'required|email'); } $validator = Validator::make(Input::all(), $rules); if ($validator->passes()) { $oldUser = clone $user; $user->displayname = Input::get('displayname'); $user->email = Input::get('email'); $user->confirmed = Input::get('confirm'); $user->prepareRules($oldUser, $user); if ($user->confirmed == null) { $user->confirmed = $oldUser->confirmed; } if (!Input::get('password')) { $user->password = Input::get('password'); $user->password_confirmation = Input::get('password_confirmation'); } else { unset($user->password); unset($user->password_confirmation); } $user->amend(); $user->saveRoles(Input::get('roles')); foreach (Input::get('user_profiles') as $id => $profile) { $pro = UserProfile::find($id); if (!empty($pro)) { $pro->fill($profile)->push(); } else { $pro = new UserProfile($profile); if ($pro->title) { $user->profiles()->save($pro); } } } foreach (Input::get('user_notes') as $id => $note) { $not = UserNotes::find($id); if (!empty($not)) { if ($note) { $not->fill(array('id' => $id, 'note' => $note))->push(); } else { $not->delete(); } } else { $not = new UserNotes(array('id' => $id, 'note' => $note, 'admin_id' => Confide::user()->id)); $user->notes()->save($not); } } Event::fire('controller.user.edit', array($user)); } else { return Api::to(array('error', Lang::get('admin/users/messages.edit.error'))) ?: Redirect::to('admin/users/' . $user->id . '/edit')->withErrors($validator); } // Get validation errors (see Ardent package) $error = $user->errors()->all(); if (empty($error)) { return Api::to(array('success', Lang::get('admin/users/messages.edit.success'))) ?: Redirect::to('admin/users/' . $user->id . '/edit')->with('success', Lang::get('admin/users/messages.edit.success')); } else { return Api::to(array('error', Lang::get('admin/users/messages.edit.error'))) ?: Redirect::to('admin/users/' . $user->id . '/edit')->with('error', Lang::get('admin/users/messages.edit.error')); } }
/** * Update the specified resource in storage. * * @param $user * @return Response */ public function postEdit($user) { // Validate the inputs $validator = Validator::make(Input::all(), User::$rules); if ($validator->passes()) { $oldUser = clone $user; $user->displayname = Input::get('displayname'); $user->email = Input::get('email'); $user->confirmed = Input::get('confirm'); $password = Input::get('password'); $passwordConfirmation = Input::get('password_confirmation'); if (!empty($password)) { if ($password === $passwordConfirmation) { $user->password = $password; // The password confirmation will be removed from model // before saving. This field will be used in Ardent's // auto validation. $user->password_confirmation = $passwordConfirmation; } else { // Redirect to the new user page return Redirect::to('admin/users/' . $user->id . '/edit')->with('error', Lang::get('admin/users/messages.password_does_not_match')); } } else { unset($user->password); unset($user->password_confirmation); } if ($user->confirmed == null) { $user->confirmed = $oldUser->confirmed; } $user->save(); // Save roles. Handles updating. $user->saveRoles(Input::get('roles')); foreach (Input::get('user_profiles') as $id => $profile) { $pro = UserProfile::find($id); if ($pro) { $pro->fill($profile)->push(); } else { $pro = new UserProfile($profile); if ($pro->title) { $user->profiles()->save($pro); } } } } else { return Redirect::to('admin/users/' . $user->id . '/edit')->with('error', Lang::get('admin/users/messages.edit.error')); } // Get validation errors (see Ardent package) $error = $user->errors()->all(); if (empty($error)) { // Redirect to the new user page return Redirect::to('admin/users/' . $user->id . '/edit')->with('success', Lang::get('admin/users/messages.edit.success')); } else { return Redirect::to('admin/users/' . $user->id . '/edit')->with('error', Lang::get('admin/users/messages.edit.error')); } }
/** * Edits a user * */ public function postEdit($user) { if (!Input::get('password')) { $rules = array('displayname' => 'required', 'email' => 'required|email', 'password' => 'min:4|confirmed', 'password_confirmation' => 'min:4'); } else { $rules = array('displayname' => 'required', 'email' => 'required|email'); } $validator = Validator::make(Input::all(), $rules); if ($validator->passes()) { $oldUser = clone $user; $user->email = Input::get('email'); $user->displayname = Input::get('displayname'); $user->prepareRules($oldUser, $user); if (!Input::get('password')) { $user->password = Input::get('password'); $user->password_confirmation = Input::get('password_confirmation'); } else { unset($user->password); unset($user->password_confirmation); } $user->amend(); foreach (Input::get('user_profiles') as $id => $profile) { $pro = UserProfile::find($id); if (!empty($pro)) { $pro->fill($profile)->push(); } else { $pro = new UserProfile($profile); if ($pro->title) { $user->profiles()->save($pro); } } } Event::fire('user.edit', array($user)); } else { return Redirect::to('user')->withInput(Input::except('password', 'password_confirmation'))->withErrors($validator); } $error = $user->errors()->all(); if (empty($error)) { return Redirect::to('user')->with('success', Lang::get('user/user.user_account_updated')); } else { return Redirect::to('user')->withInput(Input::except('password', 'password_confirmation'))->with('error', $error); } }
/** * Finds the UserProfile model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param int $id * @return DraftPlan the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModelUserProfile($id) { if (($model = UserProfile::find(['ID_USER' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }