/** * Create user profile * * @param Request $data * @param type $id int */ public static function createProfile($data, $id) { $profile = new Profile(); $profile->user_id = $id; $profile->about = "Моя информация"; $profile->save(); }
public static function socialSave($user, $info) { $prof = new Profile(); $prof->user_id = $user->id; $prof->name = $info['name']; //common if (!empty($info['first_name'])) { $prof->name = $info['first_name']; } if (!empty($info['last_name'])) { $prof->last_name = $info['last_name']; } //vk if (!empty($info['photo_rec'])) { $prof->thumb_photo = $info['photo_rec']; } if (!empty($info['photo_medium'])) { $prof->thumb_photo = $info['photo_medium']; } if (!empty($info['photo_big'])) { $prof->photo = $info['photo_big']; } //fb if (!empty($info['picture'])) { $prof->thumb_photo = $info['picture']['data']['url']; } //set default if (!$prof->thumb_photo) { $prof->thumb_photo = '/web/images/profile_thumb_photo_default.png'; } $prof->save(false); /* echo '<pre>'; print_r($info); die(); */ }
public function actionInit() { //roles //user admin psychologist school $auth = Yii::$app->authManager; //$user = $auth->createRole('user'); $adminUser = new User(); $adminUser->email = '*****@*****.**'; $adminUser->setPassword('123456'); $adminUser->generateAuthKey(); $adminUser->save(); $admin = $auth->createRole('admin'); $auth->add($admin); $averageUser = new User(); $averageUser->email = '*****@*****.**'; $averageUser->setPassword('123456'); $averageUser->generateAuthKey(); $averageUser->save(); $profile = new Profile(); $model = new SignupForm(); $model->first_name = "Юзер"; $model->last_name = "Юзерович"; $model->second_name = "Юзеров"; $profile->initProfile($model, $averageUser->id); $user = $auth->createRole('user'); $auth->add($user); /* $accessAdmin = $auth->createPermission('accessAdmin'); $accessAdmin->description = 'Access admin'; $auth->add($accessAdmin); $auth->addChild($admin, $accessAdmin);*/ //$psychologist = $auth->createRole('psychologist'); /*// add "createPost" permission $createPost = $auth->createPermission('createPost'); $createPost->description = 'Create a post'; $auth->add($createPost); // add "updatePost" permission $updatePost = $auth->createPermission('updatePost'); $updatePost->description = 'Update post'; $auth->add($updatePost); // add "author" role and give this role the "createPost" permission $author = $auth->createRole('author'); $auth->add($author); $auth->addChild($author, $createPost); // add "admin" role and give this role the "updatePost" permission // as well as the permissions of the "author" role $admin = $auth->createRole('admin'); $auth->add($admin); $auth->addChild($admin, $updatePost); $auth->addChild($admin, $author); // Assign roles to users. 1 and 2 are IDs returned by IdentityInterface::getId() // usually implemented in your User model. $auth->assign($author, 2);*/ $auth->assign($admin, 1); $auth->assign($user, 2); }
public function actionLoadProfiles() { $profileData = [['user_id' => '14', 'birthday' => '1942-02-02', 'nickname' => 'testing', 'background_img' => 'forback.png', 'avatar' => 'forback.png'], ['user_id' => '15', 'birthday' => '1998-02-02', 'nickname' => 'testing2', 'background_img' => 'forback.png', 'avatar' => 'forback.png']]; foreach ($profileData as $data) { $profile = new Profile($data); $profile->save(); } }
public function store(Request $request) { $this->validate($request, ['name' => 'required|min:1']); $profile = new ProfileModel(); $profile->name = $request->input('name'); $profile->surname = $request->input('surname'); $profile->phone = $request->input('phone'); $profile->email = $request->input('email'); $profile->save(); return redirect()->action('UsersController@index'); }
public function facebookCallback() { try { $state = $this->security->getToken(); $code = $this->request->getQuery('code'); $error = $this->request->getQuery('error'); $callback = $this->request->getQuery('callback'); if (!empty($error)) { if ($error === 'access_denied') { throw new FbCallbackException('FB authorization error: ' . $error); } else { throw new FbCallbackException('FB authorization error: ' . $error); } } if (empty($code)) { throw new FbCallbackException('Ups, something went wrong during authorization'); } $facebook_response = $this->facebook->getAccessToken($code, $state, $callback); $access_token = $facebook_response->access_token; $uid = $this->facebook->getUid($access_token); $profile = Profile::findFirst(['uid = ?0', 'bind' => [$uid]]); if (empty($profile)) { // No user, let's register it // TODO: encrypt access_token // TODO: Change default facebook avatar by ours // TODO: if user doesn't provide us with email we can't register it // TODO: facebook date format can vary $me = $this->facebook->me($access_token); // Create user $user = new User(); $user = $user->assignFromFacebook($me); if ($user->save()) { // Create profile and assign to the user $profile = new Profile(); $profile->createFromFacebook($me->id, $access_token, $user->id); return new Response(json_encode($user)); } else { throw new InvalidFbUser($user); } } else { // User already registered, update access_token $profile->save(['access_token' => $access_token]); $user = $profile->getUser(); return new Response(json_encode($user->toArray())); } } catch (FbCallbackException $e) { return $e->returnResponse(); } catch (InvalidFbUser $e) { return $e->returnResponse(); } catch (\Exception $e) { return new Response($e->getMessage(), 409); } }
public function postCreate() { $postValue = $this->getProfileInput(); $profile = new Profile(); if ($profile->validate($postValue)) { $profile->fill($postValue); $profile->save(); return redirect(route('home')); } else { return view('profile.create', compact('profile')); } }
public static function findOrCreateUser($vk_id) { if (!User::findByVkId($vk_id)) { $model = new User(); $model->vk_id = $vk_id; $model->save(); $profile = new Profile(); $profile->user_id = $model->id; $profile->save(); } return User::findByVkId($vk_id); }
public function actionRegister() { $model = new Register(); $profile = new Profile(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { if ($id = $model->register()) { $profile->createProfile($id); return $this->goHome(); } } } return $this->render('register', ['model' => $model]); }
public function actionRegister() { $model = new User(); $profile = new Profile(); if ($model->load(Yii::$app->request->getBodyParams(), '') && $model->validate()) { if ($model->validate()) { $id = $model->register(); $profile->createProfile($id); return ['success' => true]; } } else { return $model; } }
public function actionSignup() { $model = new SignupForm(); if ($model->load(Yii::$app->request->post())) { if ($user = $model->signup()) { $profile = new Profile(); if ($profile->initProfile($model, $user->id)) { if (Yii::$app->getUser()->login($user)) { return $this->goHome(); } } } } return $this->render('signup', ['model' => $model]); }
private function createShop($login, $buyer_bonus, $recommender_bonus) { $user = new User(); $user->email = $login; $user->setPassword($user->email); $user->generateAuthKey(); $user->save(false); $profile = new Profile(); $profile->user_id = $user->id; $profile->url = 'https://temp-mail.ru'; $profile->buyer_bonus = $buyer_bonus; $profile->recommender_bonus = $recommender_bonus; $profile->save(false); $this->auth->assign($this->auth->createRole(User::ROLE_SHOP), $user->id); return $user; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Profile::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; } if ($this['directions'] != '') { $query->join("inner join", "psychologist_directions", "psychologist_directions.psychologist_id=profile.user_id"); $query->andOnCondition("psychologist_directions.direction_id in ('" . $this['directions'] . "')"); } if ($this['problems'] != '') { $query->join("inner join", "psychologist_problems", "psychologist_problems.psychologist_id=profile.user_id"); $query->andOnCondition("psychologist_problems.problem_id in ('" . $this['problems'] . "')"); } if ($this['pricef'] != '') { $query->andOnCondition('price >= ' . $this->pricef); } if ($this['pricet'] != '') { $query->andOnCondition('price <= ' . $this->pricet); } $query->andFilterWhere(['id' => $this->id, 'user_id' => $this->user_id, 'has_diplom' => $this->has_diplom, 'city_id' => $this->city_id, 'updated_at' => $this->updated_at, 'created_at' => $this->created_at]); $query->andFilterWhere(['like', 'firstname', $this->firstname])->andFilterWhere(['like', 'lastname', $this->lastname])->andFilterWhere(['like', 'secondname', $this->secondname])->andFilterWhere(['like', 'education', $this->education])->andFilterWhere(['like', 'experience', $this->experience])->andFilterWhere(['=', 'gender', $this->gender]); return $dataProvider; }
public function actionView($title) { $eventId = explode('-', $title)[1]; //$training = Events::find(['id' => $eventId[1]])->one(); $training = $this->findModel($eventId); return $this->render('training', ['training' => $training, 'organizer' => Profile::findOne(['user_id' => $training['organizer_id']]), 'eventsList' => Events::find()->limit('4')->all()]); }
public function actionIndex() { if (!Yii::$app->user->identity) { return $this->goHome(); } $profile = new Profile(); $this->_profile = $profile->getProfile(); /*if(Yii::$app->user->identity->status == User::STATUS_WAIT){ return $this->goHome(); } else*/ if (Yii::$app->user->identity->status == User::STATUS_BLOCKED) { return $this->goHome(); } \Yii::$app->view->registerMetaTag(['name' => 'description', 'content' => '']); return $this->render('index', ['model' => $this->findModel(), '_profile' => $this->_profile]); }
/** * Store a newly created resource in storage. * * @param AdduserRequest $request * @return \Illuminate\Http\Response */ public function store(AdduserRequest $request) { // $input = $request->all(); // get all data // $input['confirmed'] = 1; // set confirmed to 1 // $input['password'] = Hash::make($input['password']); // hash password // // $user = User::create($input); // save above details $user = User::create(['first_name' => $request->first_name, 'last_name' => $request->last_name, 'email' => $request->email, 'confirmed' => 1, 'password' => Hash::make($request->password)]); // $profile = $user->profile()->save(new Profile); // also create new profile // $profile->apartment_id = Auth::user()->profile->defaultApartment; // get current defaultApartment // $profile->save(); // save details on profile $profile = Profile::create(['user_id' => $user->id, 'apartment_id' => Auth::user()->profile->defaultApartment]); dd(Auth::user()->profile->defaultApartment); $role = Role::whereName('user')->first(); $user->assignRole($role); //Assign Role $block_no = $request->blockno; // get block_no from profileform $floor_no = $request->floorno; // get floor_no from profileform $profile->apartments()->attach($profile->defaultApartment, ['approved' => '1', 'block_no' => $block_no, 'floor_no' => $floor_no]); // attach this profile with default apartment, with approved = 1, and block_no, floor_no according to profileform in apartment_profile pivot table. Crm_account::create(['account' => $user->first_name . $user->last_name, 'fname' => $user->first_name, 'lname' => $user->last_name, 'company' => 'Company Name', 'email' => $user->email, 'address' => 'Current Address', 'city' => 'Nagpur', 'state' => 'Maharashtra', 'zip' => '440012', 'country' => 'India']); return redirect()->back()->withMessage('User has been Added')->withStatus('success'); }
/** * Run the database seeds. * * @return void */ public function run() { DB::statement("SET foreign_key_checks = 0"); Profile::truncate(); Profile::create(array('user_id' => '1', 'defaultApartment' => '1', 'gender' => 'Male', 'mobile_no' => '8600012345', 'verified' => '1')); Profile::create(array('user_id' => '2', 'defaultApartment' => '1', 'gender' => 'Male', 'mobile_no' => '8600012345', 'verified' => '1')); }
public function run() { $faker = Faker::create('en_US'); /* * Base User Accounts */ // Mike's account $michael = User::create(['name' => 'Michael Norris', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'must_reset_password' => false, 'verify_token' => null, 'verified_on' => Carbon::now(), 'active_on' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $michaelProfile = Profile::create(['user_id' => $michael->id, 'username' => 'mstnorris', 'salutation' => 'Mr', 'first_name' => 'Michael', 'middle_name' => 'Stephen Thomas', 'last_name' => 'Norris', 'nick_name' => 'Mike', 'date_of_birth' => '1988-08-17', 'address_line_1' => '78A Sackville Road', 'address_line_2' => '', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Hove', 'address_county' => 'East Sussex', 'address_postcode' => 'BN3 3HB', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7446 990 061', 'twitter_username' => 'mstnorris', 'facebook_username' => 'mstnorris', 'google_plus_username' => 'mstnorris', 'instagram_username' => 'mstnorris', 'profile_photo_url' => '/images/mike.jpg', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $michael->profile()->save($michaelProfile); // Sezer's account $sezer = User::create(['name' => 'Sezer Tunca', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'must_reset_password' => false, 'verify_token' => null, 'verified_on' => Carbon::now(), 'active_on' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $sezerProfile = Profile::create(['user_id' => $sezer->id, 'username' => 'sezertunca', 'salutation' => 'Mr', 'first_name' => 'Sezer', 'middle_name' => '', 'last_name' => 'Tunca', 'nick_name' => 'Sezer', 'date_of_birth' => '1989-05-02', 'address_line_1' => 'Flat 4', 'address_line_2' => '15 Burlington Street', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Brighton', 'address_county' => 'East Sussex', 'address_postcode' => 'BN2 1AA', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7545 278 156', 'twitter_username' => 'sezertunca', 'facebook_username' => 'sezertunca', 'google_plus_username' => 'sezertunca', 'instagram_username' => 'sezertunca', 'profile_photo_url' => '/images/sezer.jpg', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $sezer->profile()->save($sezerProfile); // Holly's account $holly = User::create(['name' => 'Holly McNicol', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'must_reset_password' => false, 'verify_token' => null, 'verified_on' => Carbon::now(), 'active_on' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $hollyProfile = Profile::create(['user_id' => $holly->id, 'username' => 'hjmcnicol', 'salutation' => 'Miss', 'first_name' => 'Holly', 'middle_name' => 'Jane', 'last_name' => 'McNicol', 'nick_name' => 'Holly', 'date_of_birth' => '1990-05-16', 'address_line_1' => '78A Sackville Road', 'address_line_2' => '', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Hove', 'address_county' => 'East Sussex', 'address_postcode' => 'BN3 3HB', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7950 994 570', 'twitter_username' => 'hjmcnicol', 'facebook_username' => 'hjmcnicol', 'google_plus_username' => 'hjmcnicol', 'instagram_username' => 'hjmcnicol', 'profile_photo_url' => '/images/holly.jpg', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $holly->profile()->save($hollyProfile); // Jane's account $jane = User::create(['name' => 'Jane Challenger-Gillitt', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'must_reset_password' => false, 'verify_token' => null, 'verified_on' => Carbon::now(), 'active_on' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $janeProfile = Profile::create(['user_id' => $jane->id, 'username' => 'jmchallengergillitt', 'salutation' => 'Mrs', 'first_name' => 'Jane', 'middle_name' => '', 'last_name' => 'Challenger-Gillitt', 'nick_name' => 'Jane', 'date_of_birth' => '1980-01-01', 'address_line_1' => '1 Hove Road', 'address_line_2' => '', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Hove', 'address_county' => 'East Sussex', 'address_postcode' => 'BN3 3BN', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7987 654 321', 'twitter_username' => 'jmchallengergillitt', 'facebook_username' => 'jmchallengergillitt', 'google_plus_username' => 'jmchallengergillitt', 'instagram_username' => 'jmchallengergillitt', 'profile_photo_url' => 'https://placeholdit.imgix.net/~text?txt=JCG&txtsize=80&bg=eceff1&txtclr=607d8b&w=640&h=640', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $jane->profile()->save($janeProfile); // Super Administrator (User) $superU = User::create(['name' => 'Super Administrator', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $superUProfile = Profile::create(['user_id' => $superU->id, 'username' => 'superadmin', 'salutation' => 'Mr', 'first_name' => 'Super', 'middle_name' => '', 'last_name' => 'Administrator', 'nick_name' => 'SuperAdmin', 'date_of_birth' => '1980-01-01', 'address_line_1' => 'Address line 1', 'address_line_2' => '', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Hove', 'address_county' => 'East Sussex', 'address_postcode' => 'BN3 3HB', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7950 994 570', 'twitter_username' => 'superadmin', 'facebook_username' => 'superadmin', 'google_plus_username' => 'superadmin', 'instagram_username' => 'superadmin', 'profile_photo_url' => 'https://placeholdit.imgix.net/~text?txt=SUP&txtsize=80&bg=eceff1&txtclr=607d8b&w=640&h=640', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $superU->profile()->save($superUProfile); // Administrator (User) $adminU = User::create(['name' => 'Administrator', 'email' => '*****@*****.**', 'password' => bcrypt('password'), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $adminUProfile = Profile::create(['user_id' => $adminU->id, 'username' => 'admin', 'salutation' => 'Mr', 'first_name' => 'Admin', 'middle_name' => '', 'last_name' => 'Istrator', 'nick_name' => 'Admin', 'date_of_birth' => '1990-05-16', 'address_line_1' => '78A Sackville Road', 'address_line_2' => '', 'address_line_3' => '', 'address_line_4' => '', 'address_city' => 'Hove', 'address_county' => 'East Sussex', 'address_postcode' => 'BN3 3HB', 'private_email_address' => '*****@*****.**', 'mobile_number' => '+44 (0) 7950 994 570', 'twitter_username' => 'admin', 'facebook_username' => 'admin', 'google_plus_username' => 'admin', 'instagram_username' => 'admin', 'profile_photo_url' => 'https://placeholdit.imgix.net/~text?txt=ADM&txtsize=90&bg=eceff1&txtclr=607d8b&w=640&h=640', 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $adminU->profile()->save($adminUProfile); // Super Administrator (Role) $superR = Role::create(['name' => 'super-admin', 'label' => 'Super Administrator']); // Administrator (Role) $adminR = Role::create(['name' => 'admin', 'label' => 'Administrator']); // Student (Role) $studentR = Role::create(['name' => 'student', 'label' => 'Student']); //create 20 users foreach (range(1, 20) as $index) { $user_wbid = str_random(16); $user_updated_at = $faker->dateTimeBetween($startDate = '-6 months', $endDate = 'now'); $user_created_at = $faker->dateTimeBetween($startDate = '-2 years', $endDate = $user_updated_at); $user_name = $faker->firstName; $user_username = strtolower($user_name . $faker->lastName); $user_email = $user_username . $faker->companyEmail; $user_dob = $faker->dateTimeBetween($startDate = '-25 years', $endDate = '-18 years'); $user = User::create(['wbid' => $user_wbid, 'name' => $user_name, 'dob' => $user_dob, 'email' => $user_email, 'username' => $user_username, 'password' => bcrypt('password'), 'key' => str_random(11), 'confirmed' => $faker->boolean(), 'created_at' => $user_created_at, 'updated_at' => $user_updated_at]); $user->roles()->attach($studentR); } $michael->roles()->attach($studentR); $sezer->roles()->attach($studentR); $holly->roles()->attach($studentR); $superU->roles()->attach($superR); $adminU->roles()->attach($adminR); $michael->roles()->attach($superR); $sezer->roles()->attach($superR); $michael->roles()->attach($adminR); $sezer->roles()->attach($adminR); $jane->roles()->attach($adminR); }
public function callbackHasNoCode(FunctionalTester $I) { $count = User::count() + Profile::count(); $I->sendGET($this->endpoint . '/facebook/callback'); $I->seeResponseCodeIs(409); $I->seeResponseContainsJson(['status' => 'ERROR', 'message' => 'Ups, something went wrong during authorization']); $I->assertEquals($count, User::count() + Profile::count()); }
protected function findModel($id) { if (($model = Profile::findOne(['user_id' => $id])) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function run() { DB::table('profile')->delete(); ProfileModel::create(['name' => 'Robert', 'surname' => 'Lippert', 'email' => '*****@*****.**', 'phone' => '123123']); ProfileModel::create(['name' => 'Andreas', 'surname' => 'Rudat', 'email' => '*****@*****.**', 'phone' => '123123']); ProfileModel::create(['name' => 'Christopher', 'surname' => 'Stock', 'email' => '*****@*****.**', 'phone' => '123123']); ProfileModel::create(['name' => 'Andreas', 'surname' => 'Zeissner', 'email' => '*****@*****.**', 'phone' => '123123']); }
public function updateProfile() { $profile = ($profile = Profile::findOne(Yii::$app->user->id)) ? $profile : new Profile(); $profile->user_id = Yii::$app->user->id; $profile->first_name = $this->first_name; $profile->last_name = $this->last_name; return $profile->save() ? true : false; }
/** * Run the database seeds. * * @return void */ public function run() { DB::table('profiles')->delete(); $users = User::all(); foreach ($users as $user) { Profile::create(['display_name' => 'The Real Doodle Maestro', 'user_id' => $user->id]); } }
public function actionUpdateProfile() { if (!Yii::$app->user->isGuest) { if (Yii::$app->request->get('new')) { $model = new Profile(); $avatar = ""; $user_id = Yii::$app->user->id; } else { if (Yii::$app->request->get('id')) { $user_id = Yii::$app->request->get('id'); } else { $user_id = Yii::$app->user->id; } $model = Profile::find()->where(['user_id' => $user_id])->one(); if (!empty($model->avatar)) { $avatar = $model->avatar; } } if (Yii::$app->request->post()) { $model->user_id = $user_id; $model->first_name = Yii::$app->request->post('Profile')['first_name']; $model->second_name = Yii::$app->request->post('Profile')['second_name']; $model->last_name = Yii::$app->request->post('Profile')['last_name']; $model->birthday = Yii::$app->request->post('Profile')['birthday']; $model->about = Yii::$app->request->post('Profile')['about']; $model->location = Yii::$app->request->post('Profile')['location']; $model->sex = Yii::$app->request->post('Profile')['sex']; $upload = new UploadForm(); if ($upload->imageFiles = UploadedFile::getInstances($model, 'avatar')) { if (!empty($avatar)) { if (file_exists(Yii::getAlias('@webroot/uploads/image_profile/original/' . $avatar))) { unlink(Yii::getAlias('@webroot/uploads/image_profile/original/' . $avatar)); unlink(Yii::getAlias('@webroot/uploads/image_profile/xm/' . $avatar)); unlink(Yii::getAlias('@webroot/uploads/image_profile/sm/' . $avatar)); unlink(Yii::getAlias('@webroot/uploads/image_profile/lm/' . $avatar)); } } $filename = $upload->upload('image_profile/'); $model->avatar = $filename[0] . '.' . $upload->imageFiles[0]->extension; } else { $model->avatar = $avatar; } if ($model->save()) { Yii::$app->session->setFlash('success', "Профиль изменен"); return $this->redirect(['/user/view-profile', 'id' => $user_id]); } else { Yii::$app->session->setFlash('error', "Не удалось изменить профиль"); Yii::error('Ошибка записи. Профиль не изменен'); return $this->refresh(); } } else { return $this->render('update-profile', ['model' => $model]); } } else { Yii::$app->session->setFlash('error', 'Нет доступа!'); return $this->redirect('/'); } }
protected function findModelRegion($region_id) { $modelProfile = Profile::find()->where(['id' => $region_id])->one(); if ($modelProfile !== null) { return $modelProfile; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDelete($id) { if ($this->findModel(Profile::className(), $id)->delete() !== false) { $this->setFlash('success', \Yii::t('app', 'Modifications have been saved')); } else { $this->setFlash('error', \Yii::t('app', 'Modifications have not been saved')); } return $this->redirect(['/profile/index']); }
public function showUser() { header('content-type:text/html; charset=utf-8'); $user = array(); $users = Profile::getAll(); foreach ($users as $user) { var_dump($user->name); } }
/** * @return \yii\db\ActiveQuery */ public function getUsername() { if (!Yii::$app->user->isGuest) { $user = Yii::$app->user->getIdentity(); $id = $user->id; $user_id = Profile::findOne(['user_id' => $id]); return $user_id->second_name . " " . $user_id->first_name; } }
public function findByUserId($userId) { $profile = Profile::where('user_id', $userId)->first(); if ($profile) { return $profile; } else { $this->throwStoreResourceFailedException(); } }
public function run() { $faker = Faker::create(); $admin = User::create(['id' => 1, 'first_name' => 'Phillip', 'last_name' => 'Madsen', 'email' => '*****@*****.**', 'password' => bcrypt('mad15696'), 'last_login' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $adminProfile = Profile::create(['user_ id' => 1, 'username' => 'phillipmadsen', 'facebook_username' => 'phillipmadsen', 'twitter_username' => 'phillipmadsen', 'instagram_username' => 'phillipmadsen']); $admin->profile()->save($adminProfile); $phillip = User::create(['id' => 2, 'first_name' => 'Phillip', 'last_name' => 'Madsen', 'email' => '*****@*****.**', 'password' => bcrypt('mad15696'), 'last_login' => Carbon::now(), 'created_at' => Carbon::now(), 'updated_at' => Carbon::now()]); $phillipProfile = Profile::create(['user_ id' => 2, 'username' => 'phillipmadsen', 'facebook_username' => 'phillipmadsen', 'twitter_username' => 'phillipmadsen', 'instagram_username' => 'phillipmadsen']); $phillip->profile()->save($phillipProfile); }