/**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     if (!isset($data['name']) || $data['name'] == '') {
         $name = '';
         if ($data['user_type'] == 'personal') {
             $name = $data['first_name'] . ' ' . $data['last_name'];
         }
     } else {
         $name = $data['name'];
     }
     if ($data['user_type'] == 'company') {
         $name = $data['company_name'];
         $data['first_name'] = '';
         $data['last_name'] = '';
     }
     $user = new User(['is_active' => 1, 'locale' => App::getLocale(), 'name' => $name, 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
     $user->is_active = 1;
     $user->role = 'user';
     $user->type = $data['type'];
     $user->save();
     $profile = new UserProfile(['first_name' => $data['first_name'], 'last_name' => $data['last_name'], 'location' => $data['city'], 'phone' => $data['mobile'], 'last_activity' => Carbon::now()]);
     $profile->user_id = $user->id;
     $profile->type = $data['user_type'];
     $profile->save();
     return $user;
 }
Beispiel #2
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array  $data
  * @return User
  */
 protected function create(array $data)
 {
     $user = User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), 'last_activity' => \Carbon\Carbon::now()]);
     $profile = new UserProfile(['first_name' => $data['name']]);
     $profile->user_id = $user->id;
     $profile->save();
     return $user;
 }
 /**
  * Save photo
  *
  * @param \app\models\UserProfile $profile
  * @param string $photo
  * @return void
  */
 private function savePhoto($profile, $photo)
 {
     $file = $this->makeUploadedFile($photo);
     $model = new DynamicModel(compact('file'));
     $model->addRule('file', 'image', $profile->fileRules('photo', true))->validate();
     if (!$model->hasErrors()) {
         $profile->createFile('photo', $file->tempName, $model->file->name);
     }
 }
Beispiel #4
0
 /**
  * 添加对应
  * @param int $user_id 用户的 id
  * @param string $nikename 用户昵称
  * @param int $gender 性别 1男 2 女
  */
 public static function add($user_id, $nikename, $gender)
 {
     $model = new UserProfile();
     $model->gender = $gender;
     $model->nikename = $nikename;
     $model->user_id = $user_id;
     $model->update_time = time();
     $model->insert();
     return $model;
 }
 public function testAddPhoto($I)
 {
     $model = new UserProfile();
     $file = $model->createFile('photo', Yii::getAlias('@tests/_data/files/300x300.png'), '300x300.png');
     $I->click('user-2');
     $I->click('Profile');
     $I->submitForm($this->formId, [$this->formName . '[photo]' => $file->id]);
     $I->expectTo('see success');
     $I->see('Saved successfully');
     $I->seeInField($this->formName . '[photo]', $model->fileUrl('photo', $file));
 }
 /**
  * Show the application dashboard.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $user = Auth::user();
     /** @var UserProfile $profile */
     if (!($profile = $user->profile)) {
         $profile = new UserProfile();
         $profile->user_id = $user->id;
         $profile->about = 'Пусто';
         $profile->save();
     }
     return view('home', ['user' => $user, 'profile' => $profile]);
 }
Beispiel #7
0
 public function postRegisterAjax(Request $request)
 {
     // try {
     $firstname = $request->input('firstname');
     $lastname = $request->input('lastname');
     $email = $request->input('email');
     $username = $request->input('email');
     $password = $request->input('password');
     try {
         $user = User::where('email', '=', $email)->first();
         if ($user) {
             return ['success' => '0', 'results' => '', 'messages' => 'The account already exists in weDonate.', 'redirect' => ''];
         }
     } catch (Exception $e) {
         Log::error($e);
     }
     // TODO: create a globa function to create a user
     $user = new User();
     $user->uuid = Uuid::generate(4);
     $user->registered_ip = $_SERVER['REMOTE_ADDR'];
     $user->registered_provider = 'email';
     $user->last_login_ip = null;
     $user->last_login_datetime = date('Y-m-d H:i:s');
     $user->email = $email;
     $user->username = $email;
     $user->password = Hash::make($password);
     $user->referrer_code = Uuid::generate(1, '0123456');
     $user->save();
     $profile = new UserProfile();
     $profile->user_id = $user->id;
     $profile->firstname = $firstname;
     $profile->lastname = $lastname;
     if ($request->has('referrer')) {
         $profile->referrer_id = User::where('referrer_code', '=', $request->has('referrer_code'))->first();
     }
     $profile->ranking = (int) User::all()->count();
     $profile->save();
     $role = Role::where('name', '=', 'donator')->first();
     $user->attachRole($role);
     if (Auth::attempt(['username' => $email, 'password' => $password])) {
         Log::info('USer registered, id=' . $user->id);
         return ['success' => '1', 'results' => '', 'messages' => 'Successfully connected.', 'redirect' => route('getDash')];
     } else {
         return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
     }
     // } catch (Exception $e) {
     return ['success' => '0', 'results' => '', 'messages' => 'An errorred occurred.', 'redirect' => ''];
     // }
 }
 public function actionProfile($id)
 {
     $model = $this->findModel($id);
     if ($model === null) {
         throw new NotFoundHttpException('The requested page does not exist.');
     } else {
         if (Yii::$app->user->id === $model->id) {
             $profileModel = UserProfile::findOne(['user_id' => Yii::$app->user->id]);
             if (is_null($profileModel)) {
                 $profileModel = new UserProfile();
             }
             $workModel = new UserWorkExperience();
             $query = new Query();
             $query->from(UserWorkExperience::tableName());
             $query->where(['user_id' => $id]);
             $userWorkDataProvider = new ActiveDataProvider(['query' => $query]);
             $educationModel = new UserEducation();
             $query = new Query();
             $query->from(UserEducation::tableName());
             $query->where(['user_id' => $id]);
             $educationDataProvider = new ActiveDataProvider(['query' => $query]);
             $addressModel = new UserAddress();
             $query = new Query();
             $query->from(UserAddress::tableName());
             $query->where(['user_id' => $id]);
             $addressDataProvider = new ActiveDataProvider(['query' => $query]);
             if ($profileModel->load(Yii::$app->request->post()) && $profileModel->beforeSave(true) && $profileModel->save()) {
             }
             if ($workModel->load(Yii::$app->request->post()) && ($workModel->user_id = $model->id) && $workModel->beforeSave(true) && $workModel->save()) {
                 $workModel = new UserWorkExperience();
             }
             if ($educationModel->load(Yii::$app->request->post()) && ($educationModel->user_id = $model->id) && $educationModel->beforeSave(true) && $educationModel->save()) {
                 $educationModel = new UserEducation();
             }
             if ($addressModel->load(Yii::$app->request->post()) && ($addressModel->user_id = $model->id) && $addressModel->beforeSave(true) && $addressModel->save()) {
                 $addressModel = new UserAddress();
             }
             return $this->render('profile', ['model' => $model, 'profileModel' => $profileModel, 'workModel' => $workModel, 'workDataProvider' => $userWorkDataProvider, 'educationModel' => $educationModel, 'educationDataProvider' => $educationDataProvider, 'addressModel' => $addressModel, 'addressDataProvider' => $addressDataProvider]);
         } else {
             throw new NotFoundHttpException('Access Denied. You need to be owner to perform this operation.');
         }
     }
 }
Beispiel #9
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = UserProfile::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category_id' => $this->category_id, 'confirmed_at' => $this->confirmed_at, 'blocked_at' => $this->blocked_at, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'flags' => $this->flags]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'unconfirmed_email', $this->unconfirmed_email])->andFilterWhere(['like', 'registration_ip', $this->registration_ip]);
     return $dataProvider;
 }
Beispiel #10
0
 public function store(Request $request)
 {
     $rules = ['category' => 'required|numeric|exists:categories,id', 'sub_category' => 'required|numeric|exists:categories,id', 'title' => 'required|min:5|max:255', 'subtitle' => 'required|min:5', 'photo' => 'image|max:3500', 'event_date' => 'date', 'event_time' => 'date_format:H:i', 'address' => 'min:5|max:255', 'location' => 'required|numeric|exists:locations,id', 'is_priced' => 'required|boolean', 'price' => 'required_if:is_priced,1|numeric', 'is_sms' => 'boolean', 'is_email' => 'boolean', 'taskers_only' => 'boolean', 'no_comments' => 'boolean', 'agree' => 'accepted'];
     if (!$this->user) {
         $rules['name'] = 'required|min:2|max:255';
         $rules['email'] = 'required|email|unique:users,email';
         $rules['mobile'] = 'required|min:5|max:16';
     }
     $this->validate($request, $rules);
     $data = $request->all();
     if (!$this->user) {
         $user = new User(['is_active' => 1, 'locale' => App::getLocale(), 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt(substr(uniqid(), 0, 8))]);
         $user->is_active = 1;
         $user->role = 'user';
         $user->type = 'client';
         $user->save();
         $profile = new UserProfile(['first_name' => $data['name'], 'last_name' => '', 'location' => $data['location'], 'phone' => $data['mobile'], 'last_activity' => Carbon::now()]);
         $profile->user_id = $user->id;
         $profile->type = 'personal';
         $profile->save();
         Auth::login($user);
         $this->user = $user;
     }
     $task = new Task(['is_active' => 1, 'status' => 'bidding', 'category_id' => $data['sub_category'], 'location_id' => $data['location'], 'title' => $data['title'], 'subtitle' => $data['subtitle'], 'address' => $data['address'], 'price' => floatval($data['price']), 'event_date' => new Carbon($data['event_date']), 'event_time' => $data['event_time'], 'sms' => isset($data['is_sms']) ? $data['is_sms'] : 0, 'email' => isset($data['is_email']) ? $data['is_email'] : 0, 'taskers_only' => isset($data['taskers_only']) ? $data['taskers_only'] : 0, 'comments_public' => isset($data['no_comments']) ? !$data['no_comments'] : 1]);
     $task->user_id = $this->user->id;
     $task->save();
     $photo = $request->file('photo');
     if ($photo) {
         $ext = strtolower($photo->getClientOriginalExtension());
         $photoFile = TaskMapper::generatePhotoPath($task, $ext);
         $photo = $photo->move(pathinfo($photoFile, PATHINFO_DIRNAME), pathinfo($photoFile, PATHINFO_BASENAME));
         $task->photo = $photo->getFilename();
         $task->save();
     }
     return redirect('/task/show/' . $task->id);
 }
Beispiel #11
0
 /**
  * 1.3版本的通过用户的 user_id获取用户的基本信息
  * @param  int $user_id 用户的 id
  */
 public static function getUserProfileVer13($user_id)
 {
     //获取用户的昵称性别头像
     $user_avatar = UserAvatar::get($user_id);
     //用户基本信息
     $user_profile = UserProfile::getProfile($user_id);
     //认证状态
     $sign_status = UserStatus::checkSignStatus($user_id) ? 1 : 0;
     //禁言状态
     $nosay_status = UserStatus::checkPressContentStatus($user_id) ? 1 : 0;
     //返回签到天数
     $sign_count = SignRecord::getSignCount($user_id);
     //获取 uid
     $uid = UserAccount::getUid($user_id);
     //被点赞的总数,获取的顺序,发布中的数量,对应的使用的标签的数量,->太麻烦,临时增加数据表,做点赞总数的记录,用user_status的字段吧 = =
     $like_count = UserStatus::getUserLikeCount($user_id);
     //验证身份的数组
     $auth_user_arr = Yii::$app->params['auth_account'];
     //组合数据
     $user_status = ['uid' => $uid, 'avatar' => $user_avatar, 'sign_count' => $sign_count, 'banned_status' => $nosay_status, 'sign_status' => $sign_status, 'like_count' => $like_count, 'access_status' => 1, 'account_status' => (int) in_array($uid, $auth_user_arr)];
     $user_info = array_merge($user_status, $user_profile);
     return $user_info;
 }
Beispiel #12
0
 public function testDeleteOneByGuestUser()
 {
     $user = $this->createUser(['user_type' => 'guest']);
     $userToDelete = $this->createUser(['user_type' => 'guest']);
     $token = $this->tokenFromUser($user);
     $this->delete('/users/' . $userToDelete->user_id, [], ['HTTP_AUTHORIZATION' => 'Bearer ' . $token]);
     $user = User::find($userToDelete->user_id);
     $profile = UserProfile::find($userToDelete->user_id);
     $this->assertResponseStatus(403);
     $this->assertNotNull($user);
     $this->assertNotNull($profile);
 }
Beispiel #13
0
 /**
  * Creates user profile and application event
  * @param array $profileData
  */
 public function afterSignup(array $profileData = [])
 {
     $this->refresh();
     $profile = new UserProfile();
     $profile->locale = Yii::$app->language;
     $profile->load($profileData, '');
     $this->link('userProfile', $profile);
     $this->trigger(self::EVENT_AFTER_SIGNUP);
     // Default role
     $auth = Yii::$app->authManager;
     $auth->assign($auth->getRole(User::ROLE_USER), $this->getId());
 }
Beispiel #14
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request $request
  * @param  int $id
  * @return Response
  */
 public function update(Request $request, $id)
 {
     $user = User::findOrFail($id);
     $user->fill($request->all());
     $user->save();
     if (Input::file('image') and Input::file('image')->isValid()) {
         $destinationPath = 'uploads/users/user_' . $user->id . '/';
         // upload path
         $extension = Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         // Metemos la foto en el sistema
         Input::file('image')->move($destinationPath, $fileName);
         // uploading file to given path
         // Borramos las fotos del sistema
         $photos = UserProfile::where('user_id', $user->id)->get();
         if ($photos) {
             File::delete(array_pluck($photos, 'path'));
         }
         // Borramos las fotos de la BD
         UserProfile::where('user_id', $user->id)->delete();
         // Metemos la foto en la BD
         UserProfile::create(['path' => $destinationPath . $fileName, 'user_id' => $user->id]);
         //return redirect('/uploads/'.$fileName);
     }
     return redirect()->back();
 }
Beispiel #15
0
 public function run()
 {
     //UserID/Email: admin@wedonate.org & password: admin
     $user1 = new User();
     $user1->email = '*****@*****.**';
     $user1->username = '******';
     $user1->registered_provider = 'email';
     $user1->password = Hash::make('admin');
     $user1->uuid = Uuid::generate(4);
     $user1->registered_ip = '127.0.0.1';
     $user1->last_login_ip = null;
     $user1->last_login_datetime = date('Y-m-d H:i:s');
     $user1->referrer_code = Uuid::generate(1, '0123456');
     $user1->save();
     $profile1 = new UserProfile();
     $profile1->user_id = $user1->id;
     $profile1->display_name = 'Admin';
     $profile1->firstname = 'Admin';
     $profile1->lastname = 'WeDonate';
     $profile1->ranking = 0;
     $profile1->save();
     $user = new User();
     $user->email = '*****@*****.**';
     $user->username = '******';
     $user->registered_provider = 'email';
     $user->password = Hash::make('Widaudtwdm#7');
     $user->uuid = Uuid::generate(4);
     $user->registered_ip = '127.0.0.1';
     $user->last_login_ip = null;
     $user->last_login_datetime = date('Y-m-d H:i:s');
     $user->referrer_code = Uuid::generate(1, '0123456');
     $user->save();
     $profile = new UserProfile();
     $profile->user_id = $user->id;
     $profile->display_name = '#J';
     $profile->firstname = '#J';
     $profile->lastname = '';
     $profile->ranking = 1;
     $profile->save();
     $role = new Role();
     $role->name = 'developer';
     $role->display_name = 'Developer';
     $role->description = 'Developer priveleges. Everything activated.';
     $role->save();
     $user2 = new User();
     $user2->email = '*****@*****.**';
     $user2->username = '******';
     $user2->registered_provider = 'email';
     $user2->password = Hash::make('cyanacid13');
     $user2->uuid = Uuid::generate(4);
     $user2->registered_ip = '127.0.0.1';
     $user2->last_login_ip = null;
     $user2->last_login_datetime = date('Y-m-d H:i:s');
     $user2->referrer_code = Uuid::generate(1, '0123456');
     $user2->save();
     $profile2 = new UserProfile();
     $profile2->user_id = $user2->id;
     $profile2->display_name = 'Tuan Bui';
     $profile2->firstname = 'Tuan';
     $profile2->lastname = 'Bui';
     $profile2->ranking = 0;
     $profile2->save();
     $role2 = new Role();
     $role2->name = 'donator';
     $role2->display_name = 'Donator';
     $role2->description = 'Donator.';
     $role2->save();
     $user1 = User::where('email', '=', '*****@*****.**')->first();
     $user1->attachRole($role);
     $user2 = User::where('email', '=', '*****@*****.**')->first();
     $user2->attachRole($role);
     $user = User::where('email', '=', '*****@*****.**')->first();
     $user->attachRole($role2);
     $permission_admin = new Permission();
     $permission_admin->name = 'developer';
     $permission_admin->display_name = 'Developer';
     $permission_admin->description = 'Developer priveleges. Everything activated.';
     $permission_admin->save();
     $permission_donator = new Permission();
     $permission_donator->name = 'donator';
     $permission_donator->display_name = 'Donator';
     $permission_donator->description = 'Donator priveleges. Limit activated.';
     $permission_donator->save();
     $role->attachPermission($permission_admin);
     $role2->attachPermission($permission_donator);
 }
 /**
  * Upload cover image.
  * 
  * @param Request $request
  * 
  * @return AJAX
  */
 function uploadCover(Request $request)
 {
     if ($request->isMethod('POST')) {
         $rules = $this->_getCoverRules();
         $messages = $this->_getCoverMessages();
         $validator = Validator::make($request->all(), $rules, $messages);
         if ($validator->fails()) {
             return file_pong(['messages' => $validator->errors()->first()], _error(), 403);
         }
         if ($request->file('__file')->isValid()) {
             $avatar = $request->file('__file');
             $storagePath = config('frontend.coversFolder');
             $mediumSizeW = (int) config('frontend.coverMediumW');
             $mediumSizeH = (int) config('frontend.coverMediumH');
             $mediumName = generate_filename($storagePath, $avatar->getClientOriginalExtension(), ['prefix' => 'cover_', 'suffix' => "_{$mediumSizeW}x{$mediumSizeH}"]);
             $avatar->move($storagePath, $mediumName);
             $image = ImageIntervention::make($storagePath . '/' . $mediumName)->orientate();
             $image->fit($mediumSizeW, $mediumSizeH, function ($constraint) {
                 $constraint->upsize();
             });
             $image->save();
             $userProfile = user()->userProfile;
             if (is_null($userProfile)) {
                 $userProfile = new UserProfile();
                 $userProfile->user_id = user()->id;
             } else {
                 $avatarImg = unserialize($userProfile->cover_image);
                 if (isset($avatarImg[$mediumSizeW])) {
                     delete_file($storagePath . '/' . $avatarImg[$mediumSizeW]);
                 }
             }
             $userProfile->cover_image = serialize(array($mediumSizeW => $mediumName));
             $userProfile->save();
             return file_pong(['cover_medium' => $storagePath . '/' . $mediumName]);
         }
         return file_pong(['messages' => _t('opps')], _error(), 403);
     }
 }
 public function postStripe(Request $request)
 {
     // TODO: batch the updates into one call. Need a somethign that does it all sequentially.
     // TODO: Fix all this. not good to do it all here.
     //Start transaction
     DB::beginTransaction();
     try {
         $cause = Cause::where('id', $request->input('cause'))->first();
         $user = Auth::user();
         Log::debug('A donation has been made by the user: '******' to the cause name: ' . $cause->name);
         $j = User::where('id', '=', 1)->first();
         $payment = new PaymentsStripe();
         $payment->uuid = Uuid::generate(4);
         $payment->status = 'pending';
         $payment->email = $request->input('email');
         $payment->user_uuid = Auth::user()->uuid;
         $payment->cause_uuid = $request->input('cause');
         $payment->amount = $request->input('amount');
         $payment->token_id = $request->input('token_id');
         $payment->save();
         // LETS FREAKING PAY THIS MOOLAH
         $gateway = Omnipay::create('Stripe');
         $gateway->initialize(array());
         $transaction = $gateway->purchase(['amount' => (double) $payment->amount, 'currency' => 'AUD', 'token' => $payment->token_id]);
         $response = $transaction->send();
         if ($response->isSuccessful()) {
             $payment->status = 'paid';
             $payment->charge_id = $response->getTransactionReference();
             $payment->save();
             $donation = new Donation();
             $donation->uuid = Uuid::generate(4);
             $donation->type = 'single';
             $donation->status = 'paid';
             $donation->user_id = Auth::user()->id;
             $donation->cause_id = $cause->id;
             $donation->DGR = $cause->DGR;
             $donation->amount = $payment->amount;
             $donation->processor = 'stripe';
             $donation->payment_id = $payment->id;
             $donation->save();
             $splits = $this->calcDonationSplit($donation->amount);
             // WEDONATE keeps
             $wedonate_funds = WedonateFund::where('type', '=', 'single')->first();
             $amount = $wedonate_funds->amount + $splits->weDonate_keeps;
             $wedonate_funds->amount = $amount;
             $wedonate_funds->save();
             // IDONATE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'iDonate';
             $split->user_id = Auth::user()->id;
             $split->cause_id = $cause->id;
             $split->recipient_type = 'cause';
             $split->amount = $splits->iDonate;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             $cause = Cause::where('id', $cause->id)->first();
             $cause->total_donations += $split->amount;
             $cause->number_of_donations += 1;
             $cause->save();
             // UDONATE REFERRER
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'uDonate_referrer';
             $split->user_id = Auth::user()->id;
             if ($user->profile->referrer_id) {
                 $split->recipient_id = $user->profile->referrer_id;
             } else {
                 $split->recipient_id = $j->id;
             }
             $split->recipient_type = 'user';
             $split->amount = $splits->uDonate_referrer;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             // Save the udonate refferer
             $ref = UserProfile::where('user_id', $split->recipient_id)->first();
             $ref->iDonate += $splits->uDonate_referrer;
             $ref->save();
             // UDONATE REFERREE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'uDonate_referree';
             $split->user_id = $user->id;
             $split->recipient_id = $user->id;
             $split->recipient_type = 'self';
             $split->amount = $splits->uDonate_referree;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             $ref = UserProfile::where('user_id', $split->recipient_id)->first();
             $ref->iDonate += $splits->uDonate_referrer;
             $ref->save();
             // update users amount for future REFERRE
             $user->profile->referrer_amount_forward += $split->amount;
             $user->profile->total_donations += $donation->amount;
             $user->profile->donations_count += 1;
             $user->profile->iDonate += $splits->iDonate;
             $user->profile->uDonate += $splits->uDonate;
             $user->profile->weDonate += $splits->weDonate;
             $user->profile->save();
             // weDONATE
             $split = new DonationSplit();
             $split->uuid = Uuid::generate(4);
             $split->type = 'weDonate';
             $split->user_id = $user->id;
             $split->recipient_type = 'everyone';
             $split->amount = $splits->weDonate;
             $split->status = 1;
             $split->donation_id = $donation->id;
             $split->save();
             // Split the weDonate for each user
             $users_count = User::all()->count();
             $split = (double) $splits->weDonate / $users_count;
             DB::table('user_profiles')->increment('iDonate', $split);
             DB::table('user_profiles')->increment('total_donations', $split);
             // Split if for each donation too
             $causes_count = Cause::all()->count();
             $split = (double) $splits->weDonate / $causes_count;
             DB::table('causes')->where('active', 1)->increment('total_donations', $split);
             // TODO: Do rank
             $ranks = UserProfile::all();
             $ranks = $ranks->sortByDesc('total_donations');
             $count = 1;
             foreach ($ranks as $rank) {
                 $rank->ranking = $count;
                 $rank->save();
                 $count++;
             }
             Log::info('Donation paid');
             // If we reach here, then
             // data is valid and working.
             // Commit the queries!
             DB::commit();
             return redirect(route('getDonationSuccess', $payment->uuid));
         } else {
             $message = $response->getMessage();
             Log::debug($message);
             $donation_errors = new PaymentError();
             $donation_errors->uuid = Uuid::generate(4);
             $donation_errors->payment_id = $payment->id;
             $donation_errors->error_message = $message;
             $donation_errors->save();
             $user = Auth::user();
             $data = new \stdClass();
             $data->title = Log::debug('Donation Unsuccessful by the user_id=' . Auth::user()->id);
             Mail::send('emails.donate-result', $data, function ($m) {
                 $m->to($user->email, $user->name)->subject('weDonate - Donation Unsuccessful!');
             });
             // If we reach here, then
             // data is valid and working.
             // Commit the queries!
             DB::commit();
             return redirect(route('getDonationFailure', $payment->uuid));
         }
     } catch (Exception $e) {
         DB::rollback();
         throw $e;
     }
 }
Beispiel #18
0
 /**
  * Patch an entity.
  *
  * @param  string   $id
  * @param  Request  $request
  * @return Response
  */
 public function patchOne(Request $request, $id)
 {
     /** @var User $model */
     $model = $this->findOrFailEntity($id);
     // Check if the email is being changed, and initialize confirmation
     $email = $request->get('email');
     if ($email && $model->email != $email) {
         $emailConfirmToken = $model->createEmailConfirmToken($email, $model->email);
         $loginToken = $model->makeLoginToken($model->user_id);
         $this->dispatch(new SendEmailConfirmationEmail($model, $email, $emailConfirmToken, $loginToken));
         $request->merge(['email_confirmed' => null]);
     }
     // Change in email has been confirmed, set the new email
     if ($token = $request->headers->get('email-confirm-token')) {
         if (!($email = $model->getEmailFromToken($token))) {
             throw new ValidationException(new MessageBag(['email_confirmed' => 'The email confirmation token is not valid.']));
         } else {
             $model->email = $email;
         }
     }
     $this->checkEntityIdMatchesRoute($request, $id, $this->getModel(), false);
     $this->validateRequest($request->except('email'), $this->getValidationRules(), true);
     $model->fill($request->except('email'));
     $model->save();
     // Extract the profile and update if necessary
     $profileUpdateDetails = $request->get('_user_profile', []);
     if (!empty($profileUpdateDetails)) {
         /** @var UserProfile $profile */
         $profile = UserProfile::findOrNew($id);
         // The user profile may not exist for the user
         $this->validateRequest($profileUpdateDetails, UserProfile::getValidationRules(), $profile->exists);
         $profile->fill($profileUpdateDetails);
         $model->setProfile($profile);
     }
     /** @var \Tymon\JWTAuth\JWTAuth $jwtAuth */
     // Extract the credentials and update if necessary
     $credentialUpdateDetails = $request->get('_user_credential', []);
     if (!empty($credentialUpdateDetails)) {
         $credentials = UserCredential::findOrNew($id);
         /** @var UserCredential $credentials */
         $credentials->fill($credentialUpdateDetails);
         $model->setCredential($credentials);
     }
     $jwtAuth = App::make('Tymon\\JWTAuth\\JWTAuth');
     $token = $jwtAuth->fromUser($model);
     return $this->getResponse()->header('Authorization-Update', $token)->noContent();
 }
 /**
  * 修改用户头像昵称性别,post 表单提交
  */
 public function actionEdit()
 {
     $response = Yii::$app->response;
     $response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->request;
     $this_path = $this->modules_name . "/" . lcfirst($this->class_name) . "/" . lcfirst(str_replace('action', "", __FUNCTION__));
     $this_allow_version = "1.1";
     //获取参数
     $param_os = (int) $request->post("os");
     //系统
     $param_gender = (int) $request->post("gender");
     //性别 1男 2女
     $param_nikename = $request->post("nikename");
     //新的用户昵称
     $param_avatar = isset($_FILES['avatar']['error']);
     //头像上传,如果值是 true 再看 error 是不是0,如果是0就表示有对应的头像上传
     if ($param_avatar == true && $_FILES['avatar']['error'] == 0) {
         $param_avatar = TRUE;
         //头像存在
     } else {
         $param_avatar = null;
         //头像不存在
     }
     //获取token
     $headers = $request->headers;
     $header_token = $headers->get('Token') ? $headers->get('Token') : $request->post("token");
     //加密之后的设备号,做到兼容post的方式
     //验证参数是不是有空的
     $check_null = Validators::validateAllNull([$param_os, $header_token]);
     if ($check_null === FALSE) {
         //错误信息,参数不全
         return $response->data = Error::errorJson($this_path, 1001);
     }
     //验证三个参数是不是至少有一个
     $check_all_null = Validators::validateNotAllNull([$param_gender, $param_nikename, $param_avatar]);
     if ($check_all_null === FALSE) {
         //错误信息,参数不全
         return $response->data = Error::errorJson($this_path, 1002);
     }
     //测试环境本地环境对 token 不做验证
     if ($header_token == '233' && (YII_ENV_LOCAL == 'local' || YII_ENV_DEV)) {
         $uid = 1047;
     } else {
         $token_decode = RsaDecode::clientTokenToArray($header_token);
         if ($token_decode === FALSE) {
             //返回错误信息
             return $response->data = Error::errorJson($this_path, 9003);
         }
         //解密
         //验证token
         $check_user_token = TokenUser::check($token_decode['uid'], $token_decode['deviceid'], $token_decode['logintime']);
         if ($check_user_token !== "0") {
             return $response->data = Error::errorJson($this_path, $check_user_token);
         }
         $uid = $token_decode['uid'];
     }
     $user_id = UserAccount::getUserId($uid);
     //性别
     if ($param_gender) {
         $update_gender = UserProfile::editGender($user_id, $param_gender);
         //验证性别
         if (!in_array($param_gender, [1, 2])) {
             //性别输入不符
             return $response->data = Error::errorJson($this_path, 4008);
         }
         if (!$update_gender) {
             return $response->data = Error::errorJson($this_path, 5001);
         }
     }
     //昵称
     if ($param_nikename) {
         $update_nikename = UserProfile::editNikename($user_id, $param_nikename);
         if (!$update_nikename) {
             return $response->data = Error::errorJson($this_path, 5001);
         }
     }
     //头像
     if ($param_avatar) {
         $avatar_url = WebImgToLocal::simpleUploadV2($_FILES['avatar']);
         UserAvatar::changeAvatar($user_id, $avatar_url);
     }
     //返回对应的结果
     $return_json = ['request' => $this_path, 'info' => ['user_info' => App::getUserProfile($user_id)], 'version' => $this_allow_version, 'error_code' => 0, 'error' => ""];
     //接口访问记录
     CensusApi::add($user_id, $this_path);
     return $response->data = $return_json;
 }
 public function run()
 {
     DB::table('user_profiles')->delete();
     for ($i = 0; $i < $this->num_records; $i++) {
         $array = ['user_id' => $this->getRandRec(), 'image_id' => $this->getRandRec(), 'about_me' => $this->getFaker()->text];
         UserProfile::create($array);
     }
 }
 public function getDelete($provider = 'facebook')
 {
     $profile = UserProfile::where('user_id', '=', \Auth::user()->user_id)->where('provider_name', '=', $provider)->delete();
     $this->flashMessage('Sucessfully removed ' . ucfirst($provider) . '.');
     return redirect('/admin/profile');
 }
 /**
  * Finds the UserProfile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return UserProfile the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = UserProfile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function getUserRemove(Request $request, $uuid)
 {
     try {
         $user = User::where('uuid', $uuid)->first();
         $profile = UserProfile::where('user_id', $user->id)->delete();
         $user = User::where('uuid', $uuid)->delete();
         return redirect(route('getUsers'))->withFlashMessage('User Deleted Successfully.');
     } catch (Exception $e) {
         throw $e;
     }
 }
Beispiel #24
0
 public function clients($limit = 1000)
 {
     $faker = $this->faker;
     for ($i = 0; $i < $limit; $i++) {
         $user = User::create(['name' => $faker->firstName, 'email' => $faker->freeEmail, 'password' => bcrypt('1'), 'last_activity' => \Carbon\Carbon::createFromTimestamp($faker->unixTime), 'role' => 'user', 'type' => 'client', 'provider' => 'local', 'balance' => rand(0, 100)]);
         $profile = UserProfile::create(['first_name' => $user->name, 'last_name' => $faker->lastName, 'user_id' => $user->id]);
         LogMapper::log('client_register', $user->id);
         NotificationMapper::registration($user);
     }
 }
 /**
  * 第三方账户登录
  */
 public function actionTriLogin()
 {
     $response = Yii::$app->response;
     $response->format = \yii\web\Response::FORMAT_JSON;
     $request = Yii::$app->request;
     $this_path = $this->modules_name . "/" . lcfirst($this->class_name) . "/" . lcfirst(str_replace('action', "", __FUNCTION__));
     $this_allow_version = "1.1";
     //获取参数
     $param_deviceid = $request->post("deviceid");
     //设备id
     $param_clienttime = (int) $request->post("clienttime");
     //客户端时间
     $param_os = (int) $request->post("os");
     //设备终端
     $param_channel = $request->post("channel");
     //渠道
     $param_emblem = $request->post("emblem");
     //第三方的标识
     $param_type = (int) $request->post("type");
     //登录类型
     $param_gender = (int) $request->post("gender");
     //性别
     $param_nikename = $request->post("nikename");
     //昵称
     $param_avatar = $request->post("avatar");
     //头像地址
     //获取token
     $headers = $request->headers;
     $header_openid = $headers->get('Openid') ? $headers->get('Openid') : $request->post("openid");
     //加密之后的设备号,做到兼容post的方式
     //验证参数是不是有空的
     $check_null = Validators::validateAllNull([$param_deviceid, $param_channel, $param_clienttime, $header_openid, $param_os, $param_emblem, $param_type, $param_gender, $param_nikename, $param_avatar]);
     if ($check_null === FALSE) {
         //错误信息,参数不全
         return $response->data = Error::errorJson($this_path, 1001);
     }
     //验证加密
     $decode_hear_openid = RsaDecode::rsa_decode($header_openid);
     if ($decode_hear_openid !== $param_deviceid) {
         return $response->data = Error::errorJson($this_path, 9001);
     }
     //验证通过,证明了合法性
     //验证性别
     if (!in_array($param_gender, [1, 2, 3])) {
         //性别输入不符
         return $response->data = Error::errorJson($this_path, 9001);
     }
     //验证登录方式
     $login_type = $param_type + 2;
     if ($login_type < 3 || $login_type > 7) {
         //返回错误信息,错误的登录方式
         return $response->data = Error::errorJson($this_path, 4003);
     }
     //验证手机号是不是进行过注册的操作
     $user_id = UserEmblem::checkExist($param_emblem, $login_type);
     if ($user_id == 0) {
         //注册新用户
         // 获取新的uid,写入 用户基础表,写入 用户标识表 ,写入 用户头像表
         $uid = NumberOrder::getNewid(1);
         $user_id = UserAccount::add($uid, $param_channel, $param_os);
         //用户相关的标识
         UserEmblem::add($user_id, $param_emblem, $login_type);
         //获取用户的头像
         $avatar_url = WebImgToLocal::web2oss($param_avatar);
         UserAvatar::add($user_id, $avatar_url);
         //用户的基本信息
         UserProfile::add($user_id, $param_nikename, $param_gender);
         //新的
         $login_type = 1;
         //新增用户的统计
         CensusApp::addUser();
     } else {
         //获取老用户的 id
         $uid = UserAccount::getUid($user_id);
         //以前的
         $login_type = 2;
     }
     //写入token
     TokenUser::joinToken($uid, $param_deviceid, $param_clienttime, time(), time());
     //返回对应的token
     $token = RsaDecode::tokenMake($uid);
     //返回对应的结果
     $return_json = ['request' => $this_path, 'info' => ['login_type' => $login_type, 'token' => $token, 'user_info' => App::getUserProfile($user_id)], 'version' => $this_allow_version, 'error_code' => 0, 'error' => ""];
     //接口访问记录
     CensusApi::add($user_id, $this_path);
     return $response->data = $return_json;
 }