/** * Creates a new Staff model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { if (Yii::$app->user->can('admin')) { $model = new Staff(); if (Yii::$app->request->isAjax && $model->load($_POST)) { Yii::$app->response->format = 'json'; return \yii\widgets\ActiveForm::validate($model); } if ($model->load(Yii::$app->request->post())) { $user = new Users(); $user->usertype = 'Staff'; $user->password = strtolower($model->apellido1 . substr($model->rut, 5, -2)); $user->email = $model->correo; $model->save(); $user->id_orig = $model->id; $user->username = $model->nombre . " " . $model->apellido1; $user->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { throw new ForbiddenHttpException(); } }
/** * Creates a new Users model. * For ajax request will return json object * and for non-ajax request if creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $request = Yii::$app->request; $model = new Users(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Create new Users", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { return ['forceReload' => 'true', 'title' => "Create new Users", 'content' => '<span class="text-success">Create Users success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create'], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Create new Users", 'content' => $this->renderPartial('create', ['model' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); $model->setScenario('register'); $post = Yii::$app->request->post(); $formName = basename($model->className()); if ($model->load($post)) { // Default value $model->is_super_admin = isset($post[$formName]['is_super_admin']) ? $post[$formName]['is_super_admin'] : 0; $model->role = $model->is_super_admin ? Identity::ROLE_SUPERADMIN : 30; $model->fecha_conexion = isset($post[$formName]['fecha_conexion']) ? $post[$formName]['fecha_conexion'] : Yii::$app->fn->GetDate('none'); $model->fecha_modif = isset($post[$formName]['fecha_modif']) ? $post[$formName]['fecha_modif'] : Yii::$app->fn->GetDate('none'); $model->fecha_registro = isset($post[$formName]['fecha_registro']) ? $post[$formName]['fecha_registro'] : Yii::$app->fn->GetDate(); $model->id_estado = isset($post[$formName]['id_estado']) ? $post[$formName]['id_estado'] : 1; if ($model->validate()) { $model->setPassword(); $model->generateAuthKey(); if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } } // Load empty/error form return $this->render('create', ['model' => $model]); }
public function registerAction() { try { $form = new \RegisterForm(); if ($this->request->isPost()) { $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); $user = new Users(); $user->setPassword($password, $repeatPassword); $user->email = $email; $user->created_at = new \Phalcon\Db\RawValue('now()'); $user->user_name = $this->request->getPost('name', ['string', 'striptags']); $user->nickname = $this->request->getPost('nickname', 'string'); if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->auth->login($user->toArray()); $user->sendEmailAfterReg(); return $this->goToMain(); } } } catch (\Exception $e) { $this->flash->error($e->getMessage()); } $this->view->form = $form; }
/** * Action to register a new user */ public function indexAction() { $form = new RegisterForm(); if ($this->request->isPost()) { $name = $this->request->getPost('name', array('string', 'striptags')); $username = $this->request->getPost('username', 'alphanum'); $email = $this->request->getPost('email', 'email'); $password = $this->request->getPost('password'); $repeatPassword = $this->request->getPost('repeatPassword'); if ($password != $repeatPassword) { $this->flash->error('Passwords are different'); return false; } $user = new Users(); $user->username = $username; $user->password = sha1($password); $user->name = $name; $user->email = $email; $user->created_at = new \Phalcon\Db\RawValue('now()'); $user->active = 'Y'; if ($user->save() == false) { foreach ($user->getMessages() as $message) { $this->flash->error((string) $message); } } else { $this->tag->setDefault('email', ''); $this->tag->setDefault('password', ''); $this->flash->success('Thanks for sign-up, please log-in to start generating invoices'); return $this->forward('session/index'); } } $this->view->form = $form; }
/** * * @return Redirect */ public function prosesAdd() { $rules = ['username' => 'required', 'password' => 'required', 'email' => 'required|email']; $validator = Validator::make(Input::all(), $rules); /* * jika tidak valid redirect kembali ke halaman create */ if ($validator->fails()) { return Redirect::to('/users/add')->withErrors($validator); } else { /* * jika valid simpan ke database */ $in = Input::all(); $pass = $in['password']; $pass = Crypt::encrypt($pass); $user = new Users(); $user->username = $in['username']; $user->password = $pass; $user->email = $in['email']; $user->save(); /* * redirect ke index bands */ Session::flash('message', 'Successfully created band!'); return Redirect::to('/users'); } }
/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(Request $request) { if ($request->userID) { $user = Users::where("uID", $request->userID)->first(); if ($request->password) { $user->uPassword = md5($request->password); } } else { $user = new Users(); $user->uPassword = md5($request->password); $user->uRegisteredDate = date('Y-m-d'); $user->uIsActive = 1; $user->uRole = 1; $user->uUsername = $request->username; $user->uEmail = $request->email; } $user->uBirthday = date('Y-m-d', strtotime($request->birthday)); $user->uAddress = $request->address; $user->uPhone = $request->phone; $file = Input::file('image'); // $file->getRealPath() if (!is_null($file)) { $destinationPath = public_path() . '/assets/images/avatar/'; $fileName = explode(".", $file->getClientOriginalName())[0]; $fileName = $fileName . rand(1, 9999) . "." . $file->getClientOriginalExtension(); Input::file('image')->move($destinationPath, $fileName); Image::make($destinationPath . $fileName)->resize(400, 400)->save($destinationPath . '400x400/' . $fileName); $user->uAvatar = $fileName; } $user->save(); return Redirect::action('admin\\user@index'); }
public function actionReg() { $model = new RegForm(); $error = null; if ($model->load(Yii::$app->request->post()) && $model->validate()) { $user = new Users(); $user->login = Html::encode($model->login); $user->password = md5($model->password); $user->name = Html::encode($model->name); $user->email = Html::encode($model->email); $user->phone = Html::encode($model->phone); if (UploadedFile::getInstance($model, 'photo')) { $model->photo = UploadedFile::getInstance($model, 'photo'); $model->photo->saveAs('img/photo/' . $model->photo->baseName . '.' . $model->photo->extension); $photo = 'img/photo/' . $model->photo->baseName . '.' . $model->photo->extension; $user->photo = $photo; } $uc = new UserClass(); if ($uc->isUniqueLogin($user->login)) { $user->save(); return $this->render('regsuccess'); } else { $error = 'Такой логин уже существует'; } } return $this->render('reg', ['model' => $model, 'error' => $error]); }
public function userInfo($userInfo) { print_r($userInfo); $user = new Users(); $user->email = $userInfo['email']; $user->name = $userInfo['name']; $user->save(); }
public function saveAction() { if (!$this->isXmlHttpRequest()) { throw new \Exception('Неверный тип запроса!'); } $usersModel = new Users(); $data = $this->request->getPost(); if (!isset($data['id']) || !isset($data['roles_id']) || !isset($data['user']) || !isset($data['password'])) { throw new \Exception('Неверный тип запроса!'); } if ($data['action'] == 'add' && (!isset($data['lastname']) || !isset($data['firstname']) || !isset($data['secondname']) || !isset($data['org_name']))) { throw new \Exception('Неверный тип запроса!'); } $data['id'] = (int) $data['id']; if (!$data['id'] && $data['action'] != 'add') { throw new \Exception('Неверный идентификатор пользователя!'); } $data['roles_id'] = (int) $data['roles_id']; if ($data['roles_id'] == 0) { throw new \Exception('Не выбраны права пользователя!'); } $data['user'] = trim($data['user']); if ($data['user'] == '') { throw new \Exception('Не заполнено обязательное поле Email!'); } $data['password'] = trim($data['password']); if ($data['password'] == '' && $data['action'] != 'add') { unset($data['password']); } if (isset($data['password']) && mb_strlen($data['password']) < 6) { throw new \Exception('Пароль должен быть больше 6 символов!'); } if ($data['action'] == 'add') { $data['lastname'] = trim($data['lastname']); if ($data['lastname'] == '') { throw new \Exception('Не заполнено обязательное поле Фамилия!'); } $data['firstname'] = trim($data['firstname']); if ($data['firstname'] == '') { throw new \Exception('Не заполнено обязательное поле Имя!'); } $data['secondname'] = trim($data['secondname']); if ($data['secondname'] == '') { throw new \Exception('Не заполнено обязательное поле Отчество!'); } $data['org_name'] = trim($data['org_name']); if ($data['org_name'] == '') { throw new \Exception('Не заполнено обязательное поле Организация!'); } } unset($data['action']); $data['id'] = $usersModel->save($data); $usersModel->setWhere(array('id' => $data['id'])); $uData = $usersModel->select(); $this->view->data = $uData[0]; $rolesModel = new Roles(); $this->view->roles = $rolesModel->select(); }
public function actionRegistration() { $model = new Users(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['site/index']); } else { return $this->render('registration', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->user . id]); } else { return $this->render('create', ['model' => $model]); } }
protected function setUp() { $_SERVER['REQUEST_URI'] = 'index.php'; parent::setUp(); $this->controllerSite = \Yii::$app->createControllerByID('site'); $user = new Users(); $user->username = $user->password = '******'; $user->save(); }
public function reg() { $user = new Users(); $user->username = $this->username; $user->setPassword($this->password); $user->generateAuthKey(); $user->save(); return $user; }
public function insertUser($insert_user) { $user = new Users(); $user->username = $insert_user['username']; $user->password = $insert_user['password']; $user->permission = $insert_user['permission']; $user->name = $insert_user['name']; $user->pmail = $insert_user['pmail']; $user->save(); }
public function actionRegister() { $model = new Users(); $model->load(Yii::$app->request->post()); if ($model->validate()) { $model->save(); return $this->render('confirm', ['model' => $model]); } return $this->render('register', ['model' => $model]); }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(['scenario' => 'login']); // $model = new Users(['scenario' =>'login']); // error_log(print_r($model,1)); if ($model->load(Yii::$app->request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->password = md5($model->password); $model->save(); return $this->redirect(['users/index']); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); //$model->password=sha1($model->attributes['password']); //print_r(Yii::$app->request->post()); if ($model->load(Yii::$app->request->post()) && $model->save(false)) { return $this->redirect(['view', 'id' => $model->user_id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->login = md5($model->rem_login); $model->password = md5($model->rem_pas); $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @param bool $index * @param null|integer $project_id * @return mixed */ public function actionCreate($index = false, $project_id = false) { $model = new Users(); if ($project_id) { $model->project_id = $project_id; } if ($model->load(Yii::$app->request->post()) && $model->save()) { return $index ? $this->redirect(['/admin/index/user', 'id' => $model->id]) : $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
public function register() { if (!$this->validate()) { return false; } $user = new Users(); $user->login = $this->login; $user->password_hash = Yii::$app->security->generatePasswordHash($this->password); $user->save(); Yii::$app->user->login(User::findByUsername($this->login), 3600 * 24 * 30); return true; }
public function test_validates() { $user = new Users(); $user->username = '******'; $user->password = '******'; $user->access_token = 'token'; $user->save(); /* @var $user_db Users */ $user_db = Users::getUserByUsername('yurii'); $this->assertTrue($user_db->validatePassword('pass')); $this->assertTrue($user_db->validateAuthKey($user->auth_key)); }
/** * Store a newly created resource in storage. * POST * @return Response */ public function store() { $Users = new Users(); $Users->first_name = 'Michael'; $Users->last_name = 'Pierre'; $Users->age = '31'; $Users->city = 'Orlando'; $Users->state = 'Florida'; $Users->country = 'USA'; $Users->about = 'Cool Dude'; $Users->save(); return Users::where('uid', $Users->id)->get(); }
public function signup() { if ($this->validate()) { $users = new Users(); $users->name = $this->name; $users->email = $this->email; $users->status = $this->status; $users->setPassword($this->password); $users->generateAuthKey(); return $users->save() ? $users : null; } return null; }
public function actionAuthenticate() { $request = Yii::$app->request; $username = $request->post('username'); $user = Users::findByUsername($username); // Just create the user if not found if (!$user) { $user = new Users(); $user->username = $username; $user->save(); } echo json_encode(['auth' => $user->getId() ? true : false, 'id' => $user->id, 'username' => $user->username]); }
public function reg() { $user = new Users(); $user->family = $this->family; $user->name = $this->name; $user->father = $this->father; $user->login = $this->login; $user->setPassword($this->password); $user->email = $this->email; $user->phone = $this->phone; //$user->generateAuthKey(); return $user->save() ? $user : null; }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $salt = uniqid('', true); $model->password = sha1($model->password . $salt); $model->salt = $salt; if ($model->save()) { return $this->redirect(['index']); } } else { return $this->render('create', ['model' => $model]); } }
public function actionTest() { $users = []; $musers = []; for ($i = 0; $i < 5; $i++) { $no = str_pad($i + 1, 5, 0, STR_PAD_LEFT); $u = ['user_name' => 'user' . $no, 'mobile' => 'mobile' . $no, 'idcard' => 'idcard' . $no, 'create_time' => time()]; $user = new Users(); $user->attributes = $u; $user->save(); $users[] = $user; } //$user = Users::loadMultiple($musers,$users); var_dump($users); }
/** * Creates a new Users model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Users(); if ($model->load(Yii::$app->request->post())) { $model->username = $model->id; $model->password = '******'; if ($model->validate()) { $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } } else { return $this->render('create', ['model' => $model]); } }