Example #1
0
 /**
  * Sync a user with new repositories.
  *
  * @param \App\Models\User\User          $user
  * @param \Illuminate\Support\Collection $repositories
  *
  * @return void
  */
 public function sync(User $user, Collection $repositories)
 {
     $existing = $user->repositories;
     $repositories = $this->map($repositories);
     $repositories = $this->create($repositories, $existing);
     $user->repositories()->saveMany($repositories);
 }
 /**
  * Get the organisation.
  *
  * @param \App\Models\User\User $user
  * @param string                $organisation
  *
  * @return \App\Models\Organisation\Organisation
  */
 protected function getOrganisation(User $user, $organisation)
 {
     $organisation = $user->organisations()->where('name', $organisation)->first();
     if (!$organisation) {
         throw new NotFoundHttpException();
     }
     return $organisation;
 }
Example #3
0
 /**
  * Sync a user with new organisations.
  *
  * @param \App\Models\User\User          $user
  * @param \Illuminate\Support\Collection $organisations
  *
  * @return void
  */
 public function sync(User $user, Collection $organisations)
 {
     $existing = Organisation::query()->whereIn('id', $organisations->lists('id'))->get();
     $user->organisations()->detach();
     $organisations = $this->map($organisations);
     $organisations = $this->create($organisations, $existing);
     $user->organisations()->attach($organisations->lists('id')->toArray());
 }
 public function up()
 {
     $auth = Yii::$app->authManager;
     $superAdminPermission = $auth->createPermission('*/*/*');
     $superAdminPermission->description = 'Суперадминистративные права';
     $auth->add($superAdminPermission);
     $superadmin = $auth->createRole('superadmin');
     $superadmin->description = 'Суперадминистраторы';
     $auth->add($superadmin);
     $auth->addChild($superadmin, $superAdminPermission);
     $user = new User();
     $user->attributes = ['is_active' => 1, 'email' => '*****@*****.**', 'new_password' => 'test', 'roles' => ['superadmin']];
     $user->save();
 }
Example #5
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
Example #6
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = \vendor\dektrium\yii2 - user\User::findByUsername($this->username);
     }
     return $this->_user;
 }
Example #7
0
 public function index($userId = null)
 {
     $auth = auth();
     if (!$userId) {
         $userId = $auth->id();
         $isAuthUser = true;
     } else {
         $isAuthUser = $userId == $auth->id();
     }
     if ($isAuthUser) {
         $user = $auth->user();
     } else {
         $user = User::findOrFail($userId);
     }
     $count['create'] = Project::where('user_id', $userId)->count();
     $count['join'] = Project::join('project_members', function ($join) use($userId) {
         $join->on('projects.id', '=', 'project_members.project_id')->where('project_members.user_id', '=', $userId);
     })->where('projects.user_id', '<>', $userId)->count();
     $count['comment'] = 0;
     $count['collect'] = ProjectFavorite::where('user_id', $userId)->count();
     $showList = 'create';
     foreach ($count as $key => $value) {
         if ($value > 0) {
             $showList = $key;
             break;
         }
     }
     return view('user.home.index', ['userData' => $user, 'isAuthUser' => $isAuthUser, 'projectCount' => $count, 'showList' => $showList]);
 }
Example #8
0
 /**
  * Загружает резюме по идентификатору и токену
  * @param int $id
  * @return \app\models\cv\Cv
  */
 protected function loadCv($id, $token)
 {
     $cv = Cv::find()->byId($id)->withRelated()->active()->one();
     //задаем язык сайта на основе языка резюме
     if ($cv->language) {
         Yii::$app->language = $cv->language;
     }
     if (!$cv) {
         throw new NotFoundHttpException('Запись не найдена');
     }
     //проверяем права на доступ к резюме
     if (Yii::$app->user->isGuest || !Yii::$app->user->can('*/*/*') && !Yii::$app->user->can('cv/*') && !Yii::$app->user->can('cv/index')) {
         //пробуем проверить токен
         //ищем юзера по его токену
         $user = User::find()->byCvToken($token)->one();
         if (!$user) {
             throw new NotFoundHttpException('Запись не найдена');
         }
         //перебираем все разрешенные юзеру резюме, чтобы найти заданное
         $canAccess = false;
         foreach ($user->cv as $allowed) {
             if ($allowed->id !== $cv->id) {
                 continue;
             }
             $canAccess = true;
             break;
         }
         if (!$canAccess) {
             throw new NotFoundHttpException('Запись не найдена');
         }
         //отмечаем посещение для неавторизованного пользователя
         $user->visitCv($cv);
     }
     return $cv;
 }
 /**
  * @depends testFindUserByUsername
  */
 public function testValidateUser($user)
 {
     $user = User::findByUsername('admin');
     expect_that($user->validateAuthKey('test100key'));
     expect_not($user->validateAuthKey('test102key'));
     expect_that($user->validatePassword('admin'));
     expect_not($user->validatePassword('123456'));
 }
Example #10
0
 public function loginRepos($luser, $lpassword)
 {
     echo "{$luser}";
     echo "{$lpassword}";
     if ($user = User::where("name", $luser)->first()) {
         if (Hash::check($lpassword, $user->password)) {
             return view('user.index')->with("variable", $user)->with("test", "Hello there");
         }
     }
 }
Example #11
0
 public function loginUser(Request $request)
 {
     //  $logrepos = new LoginRepositori();
     //  $user = $logrepos->loginRepos($request->user,$request->password ) ;
     if ($user = User::where("name", $request->user)->first()) {
         if (Hash::check($request->password, $user->password)) {
             return view('user.index')->with("variable", $user)->with("test", "Hello there");
         }
     }
 }
Example #12
0
 public function rules()
 {
     return [[['email', 'password'], 'required'], ['email', 'email'], ['email', function () {
         $this->user = User::find()->where(['email' => $this->email])->one();
         if (!$this->user || !$this->user->validatePassword($this->password)) {
             $this->addError('password', 'Email or Password incorrect.');
         }
     }, 'when' => function () {
         return (bool) $this->email && $this->password;
     }]];
 }
Example #13
0
 public function save()
 {
     if (!$this->validate()) {
         return false;
     }
     $this->user = User::find()->where(['email' => $this->email])->one();
     if ($this->user) {
         $model = new Reset();
         $model->user_id = $this->user->id;
         return $model->save();
     }
     return true;
 }
Example #14
0
 public static function createNoticeRecord(array $options)
 {
     // 获取通知记录ID
     $noticeRecordId = $options['notice_record_id'];
     // 如果提供了接收通知的用户ID,则取得用户对应的phone
     if (isset($options['user_id'])) {
         // 对用户进行通知,list的key为user_id
         $isNoticeUser = true;
         // 如果只有一个用户,则转换为数组
         if (!is_array($options['user_id'])) {
             $options['user_id'] = [$options['user_id']];
         }
         // 将phone关联到user_id上,key为user_id,value为phone
         $list = User::assocPhoneByUserIds($options['user_id']);
     } else {
         // false,不是对站内用户进行通知,list的key为没有意义,user_id为0
         $isNoticeUser = false;
         // 如果只有一个,同样转换为数组
         if (!is_array($options['phone'])) {
             $options['phone'] = [$options['phone']];
         }
         // 设置list为这些phone
         $list = $options['phone'];
     }
     // 如果list为空,则不进行后续处理
     if (!$list) {
         return;
     }
     $time = time();
     // 当前unix时间戳
     // 为防止需要插入的记录太多,对list进行分块
     $list = array_chunk($list, 1000, true);
     // 开始遍历,并插入记录
     foreach ($list as $chunk) {
         $data = [];
         // 本次需要插入的全部记录
         // 遍历这个chunk,将每项添加至data中准备插入
         foreach ($chunk as $key => $phone) {
             $data[] = ['notice_record_id' => $noticeRecordId, 'user_id' => $isNoticeUser ? $key : 0, 'phone' => $phone, 'created_at' => $time, 'updated_at' => $time, 'status' => static::STATUS_WAIT, 'failure_reason' => ''];
         }
         static::insert($data);
         // 插入记录
     }
     // 取得插入的phones并返回,key为记录ID,value为phone
     $phones = static::where('notice_record_id', $noticeRecordId)->lists('phone', 'id');
     if ($phones) {
         $phones = $phones->toArray();
     }
     return $phones;
 }
 /**
  * @inheritdoc
  */
 public function register()
 {
     if (!$this->validate()) {
         return false;
     }
     /** @var User $user */
     $user = Yii::createObject(User::className());
     $user->setScenario('register');
     $this->loadAttributes($user);
     if (!$user->register()) {
         return false;
     }
     $message = 'Your account has been created';
     if ($this->module->enableConfirmation || $this->module->enableGeneratingPassword) {
         $message .= ' and a message with further instructions has been sent to your email';
     }
     Yii::$app->session->setFlash('info', Yii::t('user', $message));
     return true;
 }
Example #16
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['user_id' => 'user_id'])->onCondition('bmp_user.user_id is not null');
 }
Example #17
0
 /**
  * @验证手机号唯一
  */
 public function onlyPhone($phone)
 {
     $res = User::find()->select(['user_id'])->where(['user_phone' => $phone])->asArray()->one();
     return $res['user_id'];
 }
Example #18
0
 /**
  * Signs user up.
  *
  * @return 企业注册
  */
 public function actionEnterprisesignup()
 {
     $model = new Qyuser();
     if ($model->load(Yii::$app->request->post())) {
         $User = new User();
         if ($userinfo = $User->registerEnterprise($this->request->post('Qyuser'), $this->request->userIP)) {
             if ($userinfo['code'] == 1) {
                 $this->actionTotrans('成功', '登陆页', 'site/login', $userinfo);
             } else {
                 $this->actionTotrans('错误', '返回', 'site/enterprisesignup', $userinfo);
             }
         }
     }
     return $this->render('enterprisesignup', ['model' => $model]);
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $order = Order::find($id);
     $client = User::find($order->client_id);
     $products = OrderEntry::where('order_id', $order->id)->get();
     $managers = User::where('role_id', '2')->lists('name', 'id');
     return view('orders.edit', ['order' => $order, 'managers' => $managers, 'client' => $client, 'products' => $products]);
 }
 public function __construct($id)
 {
     $this->user = User::findOne($id);
 }
 /**
  * User must not subscribe lesson and not be the owner.
  *
  * @param User $user
  * @param Lesson $lesson
  * @return bool
  */
 public function subscribe(User $user, Lesson $lesson) : bool
 {
     return Lesson::whereId($lesson->id)->where('lessons.owner_id', '!=', $user->id)->where('lessons.visibility', '=', 'public')->whereNotIn('lessons.id', $user->subscribedLessons()->pluck('id'))->exists();
 }
Example #22
0
 /**
  * @author Rohit Arora
  *
  * @param $by
  *
  * @return bool
  */
 public static function isValidOrderBy($by)
 {
     return UserModel::isValidOrderBy($by);
 }
Example #23
0
 public function getChangeConfirm(Request $request)
 {
     $detail = $this->getVerifiedDetail('email', $request);
     if (is_array($detail)) {
         User::where('id', $detail['user_id'])->update([$detail['type'] => $detail['value'], $detail['type'] . '_verified_at' => time()]);
     }
     return redirect('account/set#security');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int $id
  *
  * @return Response
  */
 public function destroy($id)
 {
     $user = User::find($id);
     if ($user) {
         if ($user->delete()) {
             return response()->json(true);
         }
     }
     return response()->json('userul nu s-a putut sterge', 500);
 }
 /**
  * 处理用户创建事件
  *
  * @param unknown $uid            
  * @param unknown $truename            
  * @param unknown $phone            
  * @param unknown $identity            
  * @param unknown $created_at            
  */
 public static function handleUserCreate($uid, $truename, $phone, $identity, $created_at)
 {
     \App\Models\User\User::create(['uid' => $uid, 'truename' => $truename, 'phone' => $phone, 'identity' => $identity, 'created_at' => $created_at]);
 }
Example #26
0
 public function postInvite($id)
 {
     $this->projectId = $id = (int) $id;
     if (!$this->getProjectPermission('setting')) {
         return response()->json(['status' => false, 'message' => '没有权限进行此操作']);
     }
     $input = (string) request()->input('input');
     if (is_email($input)) {
         $type = 'email';
     } else {
         if (is_phone($input)) {
             $type = 'phone';
         } else {
             return response()->json(['status' => false, 'message' => '请输入正确的手机号或邮箱']);
         }
     }
     $user = User::hasBeenUsed($type, $input)->first();
     $invite = new ProjectInvite();
     $invite->user_id = auth()->id();
     $invite->project_id = $this->projectId;
     $invite->invite_code = substr(str_shuffle('ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'), rand(0, 27), 8);
     $invite->{'invited_user_' . $type} = $input;
     if ($user) {
         $invite->invited_user_id = $user->id;
         if ($type == 'email' && $user->phone) {
             $invite->invited_user_phone = $user->phone;
         } else {
             if ($type == 'phone' && $user->email) {
                 $invite->invited_user_email = $user->email;
             }
         }
     }
     $invite->save();
     if ($user) {
         if (!ProjectMember::where('project_id', $this->projectId)->where('user_id', $user->id)->exists()) {
             $projectMember = new ProjectMember();
             $projectMember->user_id = $user->id;
             $projectMember->user_name = $user->realname;
             $projectMember->project_id = $this->projectId;
             $projectMember->save();
             return response()->json(['status' => true, 'message' => '受邀用户成功加入项目组', 'data' => ['home' => url('user/' . $user->id), 'face' => oss_face_url($user->face, 's'), 'name' => $user->realname, 'id' => $user->id, 'isMaster' => $this->getProject()->user_id == auth()->id()], 'send' => url('project/' . $this->projectId . '/send-invite'), 'send_data' => ['invite_id' => $invite->id]]);
         } else {
             $invite->delete();
             return response()->json(['status' => false, 'message' => '受邀用户已经在项目组了']);
         }
     } else {
         return response()->json(['status' => true, 'message' => '你的邀请已发送', 'send' => url('project/' . $this->projectId . '/send-invite'), 'send_data' => ['invite_id' => $invite->id]]);
     }
 }
Example #27
0
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
 /**
  * User must be the owner of lesson exercise belongs to.
  *
  * @param User $user
  * @param Exercise $exercise
  * @return bool
  */
 public function modify(User $user, Exercise $exercise) : bool
 {
     return User::query()->join('lessons', 'lessons.owner_id', '=', 'users.id')->join('exercises', 'exercises.lesson_id', '=', 'lessons.id')->where('exercises.id', '=', $exercise->id)->where('users.id', '=', $user->id)->exists();
 }
Example #29
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  *
  * @return User
  */
 protected function create(array $data)
 {
     return User::create(['name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password'])]);
 }
Example #30
0
 /**
  * 角色关联用户
  */
 public function actionRelateUser()
 {
     $roleId = Yii::$app->request->getQueryParam('id');
     if (!preg_match('/^\\d+$/', $roleId)) {
         throw new Exception('角色ID不合法');
     }
     $roleModel = $this->findModel($roleId);
     $model = new User();
     $dataProvider = $model->search(Yii::$app->request->queryParams);
     $updateParams = Yii::$app->request->post('selection');
     if ($updateParams) {
         $userIds = $updateParams;
         if ($roleModel->updateRelateUser($userIds, $roleId, $model)) {
             return $this->redirect(['/rbac/role/relate-user', 'id' => $roleModel->role_id]);
         }
     }
     return $this->render('/rbac/role/relateUser', ['model' => $model, 'dataProvider' => $dataProvider, 'roleModel' => $roleModel]);
 }