/**
  * 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();
 }
Beispiel #2
0
 public function saveLead($input, $user = null)
 {
     if ($user == null) {
         $user = new User();
     }
     $user->role_id = $input['role_id'];
     $user->fullname = $input['fullname'];
     $user->status = 1;
     $user->parent = auth()->id();
     if ($user->save()) {
         # INSERT META DATA
         foreach ($input['meta'] as $key => $val) {
             $meta_old = ['user_id' => $user->id, 'attr' => $key];
             $meta_new = ['user_id' => $user->id, 'attr' => $key, 'value' => $val];
             $meta = UserMeta::updateOrCreate($meta_old, $meta_new);
         }
         # INSERT META FOR TOTAL FEE, WILL BE EDITABLE BY ADMIN
         $fee_old = ['user_id' => $user->id, 'attr' => 'total_fee'];
         $fee_new = ['user_id' => $user->id, 'attr' => 'total_fee', 'value' => $this->solution->totalRefferalFee($input['solutions'])];
         UserMeta::updateOrCreate($fee_old, $fee_new);
         # INSERT PIVOT DATA
         $user->solutions()->sync($input['solutions']);
     }
     return $user;
 }
Beispiel #3
0
 /**
  *	getValidSponsors.
  *
  *	@todo I'm not sure what exactly this does at first glance
  */
 public function getValidSponsors()
 {
     $collection = new Collection();
     $groups = GroupMember::where('user_id', '=', $this->id)->whereIn('role', array(Group::ROLE_EDITOR, Group::ROLE_OWNER))->get();
     foreach ($groups as $groupMember) {
         $collection->add($groupMember->group()->first());
     }
     $users = UserMeta::where('user_id', '=', $this->id)->where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', '1')->get();
     foreach ($users as $userMeta) {
         $collection->add($userMeta->user()->first());
     }
     return $collection;
 }
Beispiel #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUserMetas()
 {
     return $this->hasMany(UserMeta::className(), ['user_id' => 'id']);
 }
 public function postVerify()
 {
     $this->beforeFilter('admin');
     $request = Input::get('request');
     $status = Input::get('status');
     $accepted = array('pending', 'verified', 'denied');
     if (!in_array($status, $accepted)) {
         throw new Exception('Invalid value for verify request: ' . $status);
     }
     $meta = UserMeta::find($request['id']);
     $meta->meta_value = $status;
     $ret = $meta->save();
     return Response::json($ret);
 }
Beispiel #6
0
 public static function getAllValidSponsors()
 {
     $userMeta = UserMeta::where('meta_key', '=', UserMeta::TYPE_INDEPENDENT_SPONSOR)->where('meta_value', '=', 1)->get();
     $groups = Group::where('status', '=', Group::STATUS_ACTIVE)->get();
     $results = new Collection();
     $userIds = array();
     foreach ($userMeta as $m) {
         $userIds[] = $m->user_id;
     }
     if (!empty($userIds)) {
         $users = User::whereIn('id', $userIds)->get();
         foreach ($users as $user) {
             $row = array('display_name' => "{$user->fname} {$user->lname}", 'sponsor_type' => 'individual', 'id' => $user->id);
             $results->add($row);
         }
     }
     foreach ($groups as $group) {
         $row = array('display_name' => $group->display_name, 'sponsor_type' => 'group', 'id' => $group->id);
         $results->add($row);
     }
     return $results;
 }
Beispiel #7
0
 /**
  *	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'));
 }