本文整理汇总了PHP中backend\models\User类的典型用法代码示例。如果您正苦于以下问题:PHP User类的具体用法?PHP User怎么用?PHP User使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了User类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIndex
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: reg
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: signup
/**
* 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: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
public function getUser()
{
if ($this->_user === false) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例5: getUser
/**
* 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: fire
/**
* 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 = 'RainLab.User => ' . $login;
} else {
$login = 'Backend.User => ' . $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;
}
示例7: actionPassword
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: getUser
/**
* Finds user by [[username]]
*
* @return User|null
*/
protected function getUser()
{
if ($this->_user === null) {
$this->_user = User::findByUsername($this->username);
}
return $this->_user;
}
示例9: actionSave
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: actionSave
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'];
}
示例11: actionEdituser
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]);
}
示例12: actionStockPedidos
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: actionCreate
/**
* 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: setStatus
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]);
}
示例15: actionPedido
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;
}