示例#1
0
 public function actionIndex()
 {
     $this->layout = false;
     if (\Yii::$app->request->isAjax) {
         $user = new User();
         $data = \Yii::$app->request->post();
         $userInfo = $user->getFindUser(['name' => $data['name']]);
         $pass = md5(md5($data['password']));
         \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
         //将响应数据转json格式
         if (!$userInfo || $userInfo['password'] != $pass) {
             //验证用户登录信息
             return ['msg' => '用户名或密码错误', 'status' => 0];
         } else {
             if ($member = \common\models\User::getInstance()->getUserByPhone($userInfo['phone'])) {
                 $userInfo['member'] = $member;
             }
             $auth = \Yii::$app->authManager;
             $userRole = $auth->getAssignments($userInfo['id']);
             $role = "";
             foreach ($userRole as $k => $v) {
                 if ($k == 'admin') {
                     $role = "admin";
                     break;
                 }
                 $role .= "," . $k;
             }
             $userInfo['role'] = $role;
             $user->setUserSession($userInfo);
             //设置Session
             return ['msg' => '登录成功', 'status' => 1];
         }
     }
     return $this->render('index.html');
 }
示例#2
0
 public function reg()
 {
     $user = new User();
     $user->username = $this->username;
     $user->email = $this->email;
     $user->status = $this->status;
     $user->setPassword($this->password);
     $user->generateAuthKey();
     return $user->save() ? $user : null;
 }
示例#3
0
 /**
  * Signs user up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signup()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->username;
         $user->email = $this->email;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         if ($user->save()) {
             return $user;
         }
     }
     return null;
 }
示例#4
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->_user === false) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
示例#5
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 public function getUser()
 {
     if ($this->user === false) {
         $this->user = User::find()->andWhere(['or', ['username' => $this->username], ['email' => $this->username]])->one();
     }
     return $this->user;
 }
示例#6
0
 /**
  * Execute the console command.
  * @throws Exception
  */
 public function fire()
 {
     $login = $this->argument('login');
     if ($this->rainlab) {
         $rainlab = (bool) $this->option('rainlab');
     } else {
         $rainlab = false;
     }
     if ($rainlab) {
         $user = \RainLab\User\Models\User::where('email', '=', $login)->orWhere('username', '=', $login)->first();
     } else {
         $user = User::whereLogin($login)->first();
     }
     if (!$user) {
         return $this->error('User not found');
     }
     $password = $this->option('password');
     if ($rainlab) {
         $login = '******' . $login;
     } else {
         $login = '******' . $login;
     }
     if ($password == null) {
         $password = $this->ask('Set password for ' . $login . ' (or press Enter to skip)');
     }
     if ($password == null) {
         $password = Str::random(5);
     }
     $user->update(['password' => $password, 'password_confirmation' => $password]);
     $message = "\n  -> new password for " . $login . ": ";
     $this->comment($message . $password);
     return;
 }
 public function actionPassword()
 {
     $model = User::findOne(Yii::$app->user->id);
     $data = Yii::$app->request->post('User');
     if (count($data)) {
         if (isset($data['password'])) {
             if ($model->validateName($data['username'])) {
                 if ($model->validatePassword($data['password_old']) && $model->validateName($data['username_old'])) {
                     $model->setAttributes($data);
                     $model->setPassword($model->password);
                     if ($model->save()) {
                         Yii::$app->session->setFlash('success', '密码修改成功');
                     } else {
                         Yii::$app->session->setFlash('danger', '密码修改失败');
                     }
                 } else {
                     Yii::$app->session->setFlash('danger', '原密码有误, 请输入正确的原密码');
                 }
             } else {
                 Yii::$app->session->setFlash('danger', '用户名已存在请重试');
             }
         }
     }
     $result['model'] = $model;
     return $this->render('password', $result);
 }
示例#8
0
 /**
  * Finds user by [[username]]
  *
  * @return User|null
  */
 protected function getUser()
 {
     if ($this->_user === null) {
         $this->_user = User::findByUsername($this->username);
     }
     return $this->_user;
 }
 public function actionSave()
 {
     $this->_setJSONFormat(Yii::$app);
     $request = Yii::$app->request;
     $data = $request->post();
     $code = '1';
     if (!empty($data['_id'])) {
         $product = Product::findOne($data['_id']['$id']);
         $data['updatedAt'] = new \MongoDate();
         $code = '2';
     }
     if (empty($product)) {
         $product = new Product();
         $accessToken = Token::getToken();
         $user = User::findOne(['_id' => $accessToken->userId]);
         $data['accountId'] = $this->getAccountId();
         $data['creator'] = $user->name;
         $data['createdAt'] = new \MongoDate();
         $data['isDeleted'] = false;
     }
     if (!empty($product->accountId)) {
         unset($data['accountId']);
     }
     $product->attributes = $data;
     $product->save();
     return ['code' => $code];
 }
示例#10
0
 public function actionSave()
 {
     $accountId = $this->getAccountId();
     $request = Yii::$app->request;
     $operatorId = $request->post('operatorId', '');
     $sampleId = $request->post('sampleId', '');
     $name = $request->post('name', '');
     $quantity = $request->post('quantity', '');
     $imgUrl = $request->post('imgUrl', '');
     $operator = User::find()->where(['_id' => $operatorId])->one();
     if ($operator === null) {
         return ['code' => 1309, 'msg' => 'not login'];
     }
     if ($name == '') {
         return ['code' => 1300, 'msg' => 'name not get'];
     }
     if ($quantity == '') {
         return ['code' => 1300, 'msg' => 'quantity not get'];
     }
     $sample = Sample::find()->where(['_id' => $sampleId])->one();
     if ($sampleId == '' || $sample == null) {
         $sample = new Sample();
         $sample->usedNumber = 0;
     }
     $sample->name = $name;
     $sample->quantity = $quantity;
     $sample->operator = $operator->name;
     $sample->imgUrl = $imgUrl;
     $sample->accountId = $accountId;
     $sample->save();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK'];
 }
 public function actionEdituser()
 {
     $req = Yii::$app->request;
     //创建一个请求对象
     $form = new UserForm();
     $form->setScenario('update');
     $id = trim($req->get('id'));
     if (!is_numeric($id) || $id == 0) {
         $this->redirect(Variable::$userMange_url);
         return;
     }
     //修改
     if ($form->load($req->post()) && $form->validate()) {
         $isSuccess = (new User())->updateCusetomer($id, $form->realName, $form->nickName, $form->password, $form->email, $form->mobile, $form->userType, $form->userStatus, $form->frozenReason, $form->comeFrom);
         if ($isSuccess) {
             $form->addError('', '资料更新成功');
         } else {
             $form->addError('', '资料更新失败');
         }
     }
     $userModel = User::findOne($id);
     $form->realName = $userModel->realName;
     $form->nickName = $userModel->nickName;
     $form->password = $userModel->password;
     $form->email = $userModel->email;
     $form->mobile = $userModel->mobile;
     $form->userType = $userModel->userType;
     $form->userStatus = $userModel->userStatus;
     $form->frozenReason = $userModel->frozenReason;
     $form->comeFrom = $userModel->comeFrom;
     return $this->render(Variable::$editUser_view, ['model' => $form, 'userModel' => $userModel]);
 }
 public function actionStockPedidos($idComercio, $idRutaDiaria)
 {
     $rutaDiaria = RutaDiaria::find()->where(['id' => $idRutaDiaria])->one();
     $usuario = User::find()->where(['id' => $rutaDiaria->id_usuario])->one();
     $rutaDiariaComercio = $this->findRutaDiariaComercio($idComercio, $idRutaDiaria);
     $datosGrillaStock = [];
     $datosGrillaPedidos = [];
     $i = 0;
     if ($rutaDiariaComercio->getStocks()->count() > 0) {
         $datosStock = $this->findStockComercio($rutaDiariaComercio->id);
         foreach ($datosStock as $stock) {
             $nombreProducto = nombreProducto($stock->id_producto);
             $datosGrillaStock[$i] = ['tipo' => Yii::t('core', 'Stock'), 'producto' => $nombreProducto, 'cantidad' => $stock->cantidad];
             $i++;
         }
     }
     $i = 0;
     if ($rutaDiariaComercio->getPedidos()->count() > 0) {
         $datosPedidos = $this->findPedidosComercio($rutaDiariaComercio->id);
         foreach ($datosPedidos as $pedido) {
             $nombrePedido = nombreProducto($pedido->id_producto);
             $datosGrillaPedidos[$i] = ['tipo' => Yii::t('core', 'Order'), 'producto' => $nombrePedido, 'cantidad' => $pedido->cantidad];
             $i++;
         }
     }
     return $this->render('stockPedidos', ['model' => $rutaDiariaComercio, 'datosGrillaStock' => $datosGrillaStock, 'datosGrillaPedidos' => $datosGrillaPedidos, 'fecha' => $rutaDiaria->fecha, 'usuario' => $usuario->username, 'ruta' => $rutaDiaria->id]);
 }
示例#13
0
 /**
  * The first step of creating page
  * Use the createBasic scenario
  **/
 public function actionCreate()
 {
     $params = $this->getParams();
     $accesstoken = $this->getAccessToken();
     $token = Token::getToken($accesstoken);
     $page = new Page(['scenario' => 'createBasic']);
     $page->attributes = $params;
     $page->_id = new \MongoId();
     $page->accountId = $token->accountId;
     $userId = $token->userId;
     $user = User::findByPk($userId);
     $page->creator = ['id' => $userId, 'name' => $user->name];
     $page->url = Yii::$app->request->hostinfo . '/msite/page/' . $page->_id;
     $shortUrl = Yii::$app->urlService->shortenUrl($page->url);
     $page->shortUrl = $shortUrl['Short'];
     if ($page->validate()) {
         // all inputs are valid
         if ($page->save()) {
             return $page;
         } else {
             throw new ServerErrorHttpException(Yii::t('common', 'save_fail'));
         }
     } else {
         // valid fail, return errors
         $errors = array_keys($page->errors);
         throw new InvalidParameterException([$errors[0] => Yii::t("microSite", $errors[0] . '_field_not_empty')]);
     }
 }
示例#14
0
 public function setStatus($id, $status = 1)
 {
     if (!in_array($status, [0, 1]) || $id == 1) {
         return false;
     }
     return User::updateAll(['status' => $status], 'id = :id', [':id' => $id]);
 }
 public function actionPedido()
 {
     $params = Yii::$app->getRequest()->post();
     $usuario = User::findIdentityByAccessToken($params['muli_token']);
     $arrayProductos = $params['productos'];
     $valid = false;
     foreach ($arrayProductos as $productos) {
         $rutaDiaria = RutaDiaria::find()->where(['id_usuario' => $usuario->id])->andWhere(['fecha' => date('Y-m-d')])->one();
         $rutaDiariaComercio = RutaDiariaComercio::find()->where(['id_comercio' => $params['id_comercio']])->andWhere(['id_ruta_diaria' => $rutaDiaria->id])->one();
         $pedidoIdProd = Pedido::find()->where(['id_producto' => $productos['id_producto']])->andWhere(['id_ruta_diaria_com' => $rutaDiariaComercio->id])->one();
         if ($pedidoIdProd != null) {
             $pedido = $pedidoIdProd;
             $pedido->setAttribute('cantidad', $productos['cant']);
         } else {
             $pedido = new Pedido();
             $pedido->setAttribute('id_producto', $productos['id_producto']);
             $pedido->setAttribute('id_ruta_diaria_com', $rutaDiariaComercio->id);
             $pedido->setAttribute('cantidad', $productos['cant']);
         }
         if ($pedido->cantidad != 0) {
             if ($pedido->validate() && $pedido->save()) {
                 $valid = true;
             } else {
                 throw new BadRequestHttpException(Yii::t('mobile', 'Failed to save route with id: ' . $rutaDiariaComercio->id . ''));
             }
         } else {
             if ($pedido->validate()) {
                 $valid = true;
             } else {
                 throw new BadRequestHttpException(Yii::t('mobile', 'Failed to save route with id: ' . $rutaDiariaComercio->id . ''));
             }
         }
     }
     return $valid;
 }
示例#16
0
 /**
  * 获取用户对象
  */
 public function getUser()
 {
     if ($this->getIsNewRecord()) {
         return [];
     }
     $data = User::findOne($this->getAttribute('uid'));
     return $data;
 }
 public function actionShowTo()
 {
     \Yii::$app->response->format = Response::FORMAT_JSON;
     $id = $_POST['id'];
     $todoList = User::find()->where(['id' => $id])->with('todos')->asArray()->one();
     //print_r($done);
     return $todoList;
 }
 /**
  * Finds the User model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return User the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = User::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
示例#19
0
 public function loginAdmin()
 {
     if ($this->validate() && (User::isAdmin($this->username) || User::isSuperAdmin($this->username))) {
         return Yii::$app->user->login($this->getUser(), $this->rememberMe ? 3600 * 24 * 30 : 0);
     } else {
         return false;
     }
 }
示例#20
0
 public function actionUserList($id = 0)
 {
     if ($id) {
         return User::findOne($id)->username;
     } else {
         return $this->_list(new User(), 'user-list');
     }
 }
示例#21
0
文件: User.php 项目: Griff19/it_base
 public function getParent($id)
 {
     $usr = User::findOne(['id' => $id]);
     $cust = Customers::findOne(['customer_name' => $usr->fullname]);
     //$usr = User::findOne(['id' => $cust->user_id]);
     //var_dump($cust);
     //die;
     return $cust->typeprices_id;
 }
示例#22
0
 public function afterFind()
 {
     parent::afterFind();
     $manager = \Yii::$app->authManager;
     $role = $manager->getRolesByUser($this->id);
     if ($role) {
         $this->role = array_keys($role)[0];
     }
 }
示例#23
0
 public function actionUpdate($id)
 {
     if ($this->isPost) {
         $params = $this->request->post('User');
         $res = $this->client->put('/user/{id}', $params, ['id' => $id]);
         if ($this->client->isValid) {
             return '';
         } else {
             throw new UserError($this->client->errors);
         }
     } else {
         $res = $this->client->get('/user/{id}', ['id' => $id]);
         $model = new User();
         $model->isNewRecord = false;
         $model->setAttributes($res, false);
         return $this->render('user_update', ['model' => $model]);
     }
 }
 public function findBusqueda()
 {
     $data = $this->find();
     $resultado = [];
     foreach ($data as $ruta) {
         $resultado[$ruta->id] = ['id' => $ruta->id, 'dia' => $ruta->dia, 'esActivo' => $ruta->esActivo, 'user' => User::findOne($ruta->id_usuario)->username];
     }
     return $resultado;
 }
示例#25
0
 /**
  * @return bool
  */
 public function isManager()
 {
     $model = User::find()->where(['username' => $this->username])->andWhere(['status' => 1])->one();
     $manager = Manager::find()->where(['user_id' => $model->id, 'status' => 1])->one();
     if ($manager) {
         return true;
     }
     return false;
 }
 public function boot()
 {
     \Backend\Models\User::extend(function ($model) {
         $model->belongsTo['team'] = ['Rafie\\SitepointDemo\\Models\\Team'];
     });
     \Backend\Controllers\Users::extendListColumns(function ($list) {
         $list->addColumns(['team' => ['label' => 'Team', 'relation' => 'team', 'select' => 'name']]);
     });
 }
示例#27
0
 /**
  * 用户信息读取
  * @return [type] [description]
  */
 public function actionUserInfo()
 {
     $id = intval($this->getParam('id', '', "ID是必须存在的"));
     $info = User::findIdentity($id);
     if (!empty($info)) {
         return print_r($info->attributes);
     } else {
         $this->out(Self::EXP_EMPTY, Self::EXP_EMPTY_TXT, '', 'PAGE');
     }
 }
示例#28
0
 public function actionUpdate()
 {
     $model = User::find()->where(['id' => \App::$app->user->identity->getId()])->One();
     $model->setScenario('admin-update');
     if ($model->load(\App::$app->request->post()) && $model->save()) {
         return $this->redirect(['update', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
示例#29
0
 public function beforeAction($action)
 {
     if (!$this->isLogin()) {
         $this->layout = false;
         return $this->redirect("/admin/login");
         //用户未登录自动跳转至登录页
     }
     $user = new User();
     $user->setUser(\Yii::$app->session->get(USER_SESSION));
     \Yii::$app->view->params['user'] = $user->getUser();
     // 当前用户
     $this->user = $user;
     $this->isCan();
     //权限验证
     $this->assign('currentUserRole', $user->getUser()['role']);
     $this->assign('currentUserId', $user->getUser()['id']);
     return parent::beforeAction($action);
     // TODO: Change the autogenerated stub
 }
示例#30
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = User::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'role' => $this->role, 'status' => $this->status, 'truename' => $this->truename, 'realcard' => $this->realcard, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'username', $this->username])->andFilterWhere(['like', 'username', $this->truename])->andFilterWhere(['like', 'username', $this->realcard])->andFilterWhere(['like', 'auth_key', $this->auth_key])->andFilterWhere(['like', 'password_hash', $this->password_hash])->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])->andFilterWhere(['like', 'email', $this->email])->andFilterWhere(['>', 'created_at', strtotime($this->created_at)]);
     return $dataProvider;
 }