/** * Saves user submissions for Independent Sponsor requests. */ public function putRequest() { //Validate input $rules = array('address1' => 'required', 'city' => 'required', 'state' => 'required', 'postal_code' => 'required', 'phone' => 'required'); $validation = Validator::make(Input::all(), $rules); if ($validation->fails()) { return Response::json($this->growlMessage($validation->messages()->all(), 'error'), 400); } //Add new user information to their record $user = Auth::user(); $user->address1 = Input::get('address1'); $user->address2 = Input::get('address2'); $user->city = Input::get('city'); $user->state = Input::get('state'); $user->postal_code = Input::get('postal_code'); $user->phone = Input::get('phone'); $user->save(); if (!$user->getSponsorStatus()) { //Add UserMeta request $request = new UserMeta(); $request->meta_key = UserMeta::TYPE_INDEPENDENT_SPONSOR; $request->meta_value = 0; $request->user_id = $user->id; $request->save(); } return Response::json(); }
/** * admin_contact. * * Sets the user as an admin contact for the site * * @param unknownType $setting * * @return bool||void * * @todo References to this should be removed. We're allowing all admins to determine notification subscriptions */ public function admin_contact($setting = null) { if (isset($setting)) { $meta = $this->user_meta()->where('meta_key', '=', 'admin_contact')->first(); if (!isset($meta)) { $meta = new UserMeta(); $meta->user_id = $this->id; $meta->meta_key = 'admin_contact'; $meta->meta_value = $setting; $meta->save(); return true; } else { $meta->meta_value = $setting; $meta->save(); return true; } } if (!$this->hasRole('Admin')) { return false; } $meta = $this->user_meta()->where('meta_key', '=', 'admin_contact')->first(); if (isset($meta)) { $this->admin_contact = $meta->meta_value == '1' ? true : false; } else { $this->admin_contact = false; } }
/** * putEdit. * * User's put request to update their profile * * @param User $user * * @return Illuminate\Http\RedirectResponse */ public function putEdit(User $user) { if (!Auth::check()) { return Response::json($this->growlMessage('Please log in to edit user profile', 'error'), 401); } elseif (Auth::user()->id != $user->id) { return Response::json($this->growlMessage('You do not have access to that profile.', 'error'), 403); } elseif ($user == null) { return Response::error('404'); } if (strlen(Input::get('password')) > 0) { $user->password = Input::get('password'); } $verify = Input::get('verify_request'); $user->email = Input::get('email'); $user->fname = Input::get('fname'); $user->lname = Input::get('lname'); $user->url = Input::get('url'); $user->phone = Input::get('phone'); $user->verify = $verify; // Don't allow oauth logins to update the user's data anymore, // since they've set values within Madison. $user->oauth_update = false; if (!$user->save()) { $messages = $user->getErrors()->toArray(); $messageArray = []; foreach ($messages as $key => $value) { //If an array of messages have been passed, push each one onto messageArray if (is_array($value)) { Log::info($value); foreach ($value as $message) { array_push($messageArray, $message); } } else { //Otherwise just push the message value array_push($messageArray, $value); } } return Response::json($this->growlMessage($messageArray, 'error'), 400); } if (isset($verify)) { $meta = new UserMeta(); $meta->meta_key = 'verify'; $meta->meta_value = 'pending'; $meta->user_id = $user->id; $meta->save(); Event::fire(MadisonEvent::VERIFY_REQUEST_USER, $user); return Response::json($this->growlMessage(['Your profile has been updated', 'Your verified status has been requested.'], 'success')); } return Response::json($this->growlMessage('Your profile has been updated.', 'success')); }