Пример #1
0
 public function onAvatarSave()
 {
     $user = Auth::getUser();
     $avatar = post('avatar');
     if ($avatar) {
         UserExtend::uploadAvatar($user, $avatar);
     }
     return ['.avatar-image' => '<img src="' . $user->avatar->getThumb(100, 100) . '"/>', '.modal-body' => "<script type='text/javascript'>\$('button.close').click();</script>"];
 }
Пример #2
0
 /**
  * Register a user
  *
  * @param array $data
  * An array of attributes to register a user.
  * Any fields that are not properties on the user object
  * Will be applied to the Usermeta object
  *
  * @param array $rules
  * A set of validation rules to validate against
  * see http://laravel.com/docs/5.1/validation
  *
  * @return User $user
  * return the user object after registration
  */
 public static function register($data, $rules = [])
 {
     $rules += ['first_name' => 'required|min:2', 'last_name' => 'required|min:2', 'email' => 'required|email|between:2,64', 'password' => 'required|min:6', 'password_confirmation' => 'required|min:6'];
     Event::fire('auth.preRegister', [$data, $rules]);
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         throw new ValidationException($validation);
     }
     /*
      * Register user
      */
     $requireActivation = UserSettings::get('require_activation', true);
     $automaticActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_AUTO;
     $userActivation = UserSettings::get('activate_mode') == UserSettings::ACTIVATE_USER;
     /*
      * Data altercations
      */
     $data['first_name'] = ucwords($data['first_name']);
     $data['last_name'] = ucwords($data['last_name']);
     $data['birth_date'] = UserExtend::parseBirthdate($data['birthday']);
     $data['phone'] = UserExtend::parsePhone($data['phone']);
     $data['email_optin'] = isset($data['email_optin']) ? $data['email_optin'] : false;
     // Split the data into whats required for the user and usermeta models
     $userData = ['name' => $data['first_name'] . ' ' . $data['last_name'], 'password' => $data['password'], 'password_confirmation' => $data['password_confirmation'], 'email' => $data['email'], 'street_addr' => $data['street_addr'], 'city' => $data['city'], 'state' => $data['state'], 'zip' => $data['zip'], 'phone' => $data['phone']];
     $user = Auth::register($userData, $automaticActivation);
     // Save user metadata
     $usermeta = Usermeta::create($data);
     $user->metadata()->save($usermeta);
     if (isset($data['avatar'])) {
         UserExtend::uploadAvatar($user, $data['avatar']);
     }
     /*
      * Activation is by the user, send the email
      */
     if ($userActivation) {
         $this->sendActivationEmail($user);
     }
     /*
      * Automatically activated or not required, log the user in
      */
     if ($automaticActivation || !$requireActivation) {
         Auth::login($user);
     }
     if ($user) {
         /*
          * Fire event that user has registered
          */
         Event::fire('auth.register', [$user]);
         return $user;
     }
     return false;
 }
Пример #3
0
 /**
  * @SWG\Definition(
  *     definition="request.avatar",
  *     type="object",
  *     required={"source"},
  *     @SWG\Property(
  *         description="Source can be one of the URLs returned by  users/profile-options/avatar endpoint or by uploading a Base64 encode string of a JPG, PNG or GIF",
  *         property="source",
  *         type="string"
  *     )
  * )
  * 
  * @SWG\Post(
  *     path="users/{id}/upload-avatar",
  *     summary="Change user avatar",
  *     description="Change user avatar. Avatar must be a valid JPG, GIF or PNG. And not bigger that 400x400 pixels.",
  *     tags={ "user"},
  *
  *     @SWG\Parameter(
  *         description="ID of user to fetch",
  *         format="int64",
  *         in="path",
  *         name="id",
  *         required=true,
  *         type="integer"
  *     ),
  *
  *     @SWG\Parameter(
  *         description="Avatar payload",
  *         name="body",
  *         in="body",
  *         required=true,
  *         schema=@SWG\Schema(ref="#/definitions/request.avatar")
  *     ),
  *     @SWG\Response(
  *         response=200,
  *         description="Successful response",
  *         @SWG\Schema(
  *              @SWG\Property(
  *                  property="success",
  *                  type="boolean"
  *              )
  *         )
  *     ),
  *     @SWG\Response(
  *         response=500,
  *         description="Unexpected error",
  *         @SWG\Schema(ref="#/definitions/error500")
  *     ),
  *     @SWG\Response(
  *         response=404,
  *         description="User not found",
  *         @SWG\Schema(ref="#/definitions/UserError404")
  *     )
  * )
  */
 public function uploadAvatar($userId)
 {
     if (is_null($user = User::find($userId))) {
         return Response::api()->errorNotFound('User not found');
     }
     $data = Request::all();
     $rules = ['source' => 'required'];
     $validation = Validator::make($data, $rules);
     if ($validation->fails()) {
         return $this->errorDataValidation('Data fails to validated', $validation->errors());
     }
     if ($source = array_get($data, 'source', null)) {
         // Check if is a selected avatar from the theme
         $avatars = $this->getThemeAvatarOptions();
         $avatars = array_keys($avatars);
         $keyAvatar = trim(strtolower(basename(basename($source))));
         if (in_array($keyAvatar, $avatars)) {
             UserExtend::uploadAvatar($user, $source);
         } else {
             UserExtend::uploadAvatarFromString($user, $source);
         }
         return ['success' => true];
     }
 }