public function store() { $rules = array('email' => 'unique:users|required|email'); $validate = Validator::make(Input::all(), $rules); if ($validate->fails()) { $msg = 'Пользователь с этим емайлом уже существует на нашей платформе.'; return Redirect::to('/')->withErrors($validate)->withInput()->with('msg', $msg); } else { $user = new User(); $userInfo = new UserInfo(); $userMoney = new UserMoney(); $userInfo->lat = 0; $userInfo->long = 0; $userInfo->save(); $userMoney->save(); $user->user_info_id = $userInfo->id; $user->user_money_id = $userMoney->id; $user->email = Input::get('email'); $user->role = 2; $user->awaiting_award = 0; $user->investor = 0; $user->registration_code = str_random(64); $password = str_random(12); $user->password = Hash::make($password); $user->registration_status = 0; $user->save(); $data = ['code' => $user->registration_code, 'password' => $password]; Mail::send('emails.confirmation', $data, function ($message) { $message->to(Input::get('email'), 'test')->subject('Спасибо за регистрацию на нашей платформе!'); }); $msg = 'Вам был послан емайл, он содержит линк и пароль для подтверждения вашего емайла, '; return Redirect::to('/')->with('msg', $msg); } }
public function postCreate() { $vCode = str_random(120); $emailChecker = User::where('email', '=', Input::get('email'))->first(); if (!empty($emailChecker)) { return 3; } $unameChecker = User::where('username', '=', Input::get('uname'))->first(); //if(!empty($unameChecker)) //{ //return 4; //} $user = new User(); $user->email = Input::get('email'); $user->username = Input::get('uname'); if (!empty(Input::get('pass'))) { $user->password = Hash::make(Input::get('pass')); } else { $tempPass = str_random(6); $user->password = Hash::make($tempPass); } $user->vCode = $vCode; if ($user->save()) { $userInfo = new UserInfo(); $userInfo->user_id = $user['id']; $userInfo->lastname = Input::get('lname'); $userInfo->firstname = Input::get('fname'); $userInfo->middleInitial = Input::get('mname'); $userInfo->address = Input::get('address'); $userInfo->contactNo = Input::get('contact'); $userInfo->email = Input::get('email'); if ($userInfo->save()) { if (!empty(Input::get('pass'))) { $emailcontent = array('username' => $user->username, 'link' => URL::route('confirmation', [$vCode, $user->id])); Mail::send('emails.confirmation.index', $emailcontent, function ($message) { $message->to(Input::get('email'), 'Kalugdan Garden Resort')->subject('Kalugdan Garden Resort Confirmation Email'); }); return 1; } else { $emailcontent = array('tempPass' => $tempPass, 'email' => Input::get('email'), 'username' => $user->username, 'link' => URL::route('confirmation', [$vCode, $user->id])); Mail::send('emails.confirmation.walk-in', $emailcontent, function ($message) { $message->to(Input::get('email'), 'Kalugdan Garden Resort')->subject('Kalugdan Garden Resort Confirmation Email'); }); return 1; } } } else { //return View::make('index')->with('mt', "HOME")->with('alert', 'fail')->with('msg', 'An error occured while creating the user. Please try again.'); //return Redirect::Route('home')->with('fail','An error occured while creating the user. Please try again.'); return 2; } }
public static function addAttr($uid, $type, $name, $value) { if (!$uid || !$type || !$name || !$value) { return false; } $info = UserInfo::model()->find("uid={$uid} AND classify='{$type}' AND name='{$name}'"); if (!$info) { $data = array('uid' => $uid, 'classify' => $type, 'name' => $name, 'value' => $value); $model = new UserInfo(); $model->attributes = $data; return $model->save(); } else { return UserInfo::model()->updateByPk($info['id'], array('value' => $value)); } }
/** * 新用户注册 * */ public function actionRegister() { $this->layout = " "; Yii::app()->clientScript->registerScriptFile(Yii::app()->theme->baseUrl . '/js/jquery-1.9.1.js'); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/login.css'); $username = Yii::app()->request->getQuery('username', null); $phone = Yii::app()->request->getQuery('phone', null); $email = Yii::app()->request->getQuery('email', null); $model = new User('create'); if (isset($_POST['User'])) { $model->attributes = $_POST['User']; if ($model->validate()) { $code_model = Temp::model()->findByPk(trim($model->phone)); if (!empty($code_model)) { if (time() - $code_model->time <= 180) { if ($model->sms_code == $code_model->code) { if ($model->save()) { $userInfo = new UserInfo(); $userInfo->userId = $model->id; $userInfo->username = $model->username; $userInfo->phone = $model->phone; $userInfo->save(); $this->redirect(array('registerSuccess')); } } else { $model->addError('sms_code', '验证码不正确'); } } else { $model->addError('sms_code', '验证码已失效,请重新获取'); } } else { $model->addError('sms_code', '验证失败,请重新获取'); } } } if (!empty($username) && trim($username) != '您的姓名') { $model->username = $username; } if (!empty($phone) && trim($phone) != '您的电话') { $model->phone = $phone; } if (!empty($email) && trim($email) != '您的邮箱') { $model->email = $email; } $sms_list = Sms::model()->findAll(); $link_list = Link::model()->findAll(); $this->render('create', array('model' => $model, 'sms_data' => $sms_list[0], 'link_list' => $link_list)); }
public function actionRegistration() { $msg = ''; $model = new UserForm('registration'); if (Yii::app()->request->isPostRequest && !empty($_POST['UserForm'])) { $model->setAttributes($_POST['UserForm']); if ($model->validate()) { $user = new UserModel(); $user->setAttributes(['email' => $model->email, 'type' => $model->type, 'password' => UserModel::model()->cryptPass($pass = UserModel::model()->genPassword()), 'hash' => $hash = UserModel::model()->genHash($pass)], FALSE); $user->save(); $info = new UserInfo(); $info->setAttributes(['user_id' => $user->id, 'name' => $model->name, 'surname' => $model->surname], FALSE); $info->save(); Yii::app()->email->send($model->email, 'Регистрация', 'Ваш пароль:' . $pass . '. Для подтверждения учетной записи перейдите по ссылке: ' . $this->createAbsoluteUrl('access/accept', ['hash' => $hash])); $msg = 'Спасибо за регистрацию! проверти почту'; } } $this->render('registration', ['model' => $model, 'msg' => $msg]); }
public function saveInfo() { $fname = Input::get('fname'); $lname = Input::get('lname'); $mname = Input::get('mname'); $address = Input::get('address'); $contact = Input::get('contact'); $email = Input::get('email'); $getInformation = new UserInfo(); $getInformation['firstname'] = $fname; $getInformation['lastname'] = $lname; $getInformation['middleInitial'] = $mname; $getInformation['address'] = $address; $getInformation['contactNo'] = $contact; $getInformation['email'] = $email; if ($getInformation->save()) { $allReserves = UserInfo::all(); foreach ($allReserves as $allReserve) { $response[] = array("reserve_id" => $allReserve['id'], "fname" => $allReserve['firstname'], "lname" => $allReserve['lastname'], "mname" => $allReserve['middleInitial'], "address" => $allReserve['address'], "contact" => $allReserve['contactNo'], "email" => $allReserve['email']); } } return $response; }
/** * Logs in the user using the given name and password in the model. * @return boolean whether login is successful */ public function register() { $user = new User(); $userInfo = new UserInfo(); $user->email = $this->email; $user->plainPassword = $this->password; if ($user->save()) { $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->name = $this->name; $userInfo->bio = $this->bio; // $userInfo->status="created"; $userInfo->addTime = time(); $userInfo->status = "created"; if ($userInfo->save()) { /** * added by lsy 20130819 * assign roles after registration HERE */ // $authorizer = Yii::app()->getModule("rights")->getAuthorizer(); // $authorizer->authManager->assign('Authenticated', $userInfo->id); /** * added by lsy 20130819 */ //注册成功后自动登录 //$identity=new UserIdentity($this->email,$this->password); //$identity->authenticate(); //Yii::app()->user->login($identity,0); // Yii::import("ext.sendcloud.ESendCloud"); // $sendCloud = new ESendCloud(); return true; } else { $user->delete(); } } return false; }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new UserInfo(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['UserInfo'])) { $model->attributes = $_POST['UserInfo']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->userId)); } } $this->render('create', array('model' => $model)); }
public function addUser($usuario) { log::info("creacion usuario"); $data['usuario'] = $usuario; $nombre = isset($data['usuario']['nombre']) ? $data['usuario']['nombre'] : ''; $ap = isset($data['usuario']['apellido_paterno']) ? $data['usuario']['apellido_paterno'] : ''; $am = isset($data['usuario']['apellido_materno']) ? $data['usuario']['apellido_materno'] : ''; $id_tipo_donador = isset($data['usuario']['id_tipo_donador']) ? $data['usuario']['id_tipo_donador'] : ''; $donacion = isset($data['usuario']['donacion_info']) ? $data['usuario']['donacion_info'] : ''; $username = isset($data['usuario']['username']) ? $data['usuario']['username'] : ''; $password = isset($data['usuario']['password']) ? $data['usuario']['password'] : ''; //die(); if (!$data['usuario']) { return false; } $usuario = User::select('username')->where('username', '=', $data['usuario']['username'])->first(); if (count($usuario) > 0) { log::info("dada"); return Response::json(array('error' => "500", 'error_message' => "Ya existe un usuario con esta cuenta")); } else { try { $usuarioInfo = new UserInfo(); $usuarioInfo->nombre = trim($nombre); $usuarioInfo->apellido_paterno = trim($ap); $usuarioInfo->apellido_materno = trim($am); $usuarioInfo->id_tipo_donador = trim($id_tipo_donador); $usuarioInfo->donacion_info = trim($donacion); $usuarioInfo->save(); log::info("inseted"); log::info($usuarioInfo); if ($data['usuario']['contacto']) { $usuario = UserInfo::find($usuarioInfo->id_usuario_info); $arrContactos = array(); log::info("find"); log::info($usuario); log::info("contacto"); log::info($usuario->contactos); $usuario->contactos()->detach(); if ($data['usuario']['contacto'] && is_array($data['usuario']['contacto'])) { foreach ($data['usuario']['contacto'] as $value) { $arrContactos[] = array('id_tipo_contacto' => $value['tipo'], 'dato' => $value['valor']); } } $usuario->contactos()->attach($arrContactos); } $login = new User(); $login->username = trim($username); $login->password = md5(trim($password)); $login->id_usuario_info = $usuarioInfo->id_usuario_info; $login->save(); return Response::json(array('error' => "200", 'error_message' => 'Se han guardado los datos')); } catch (Exception $ex) { return Response::json(array('error' => "500", 'error_message' => $ex->getMessage())); } } }
protected function connectSamebookUser($samebookUser) { $user = User::model()->findByAttributes(array('email' => $samebookUser['email'])); if (!$user) { $user = new User(); $user->email = $samebookUser['email']; $user->password = $samebookUser['pwd']; $user->salt = $samebookUser['salt']; if ($user->save()) { $userInfo = new UserInfo(); $userInfo->name = $samebookUser['username']; $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->introduction = $samebookUser['bio']; $userInfo->addTime = time(); $userInfo->status = 'ok'; $userInfo->save(); } } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //列入oauth表 if (empty($userInfo->oauth)) { $oauth = new Oauth(); $oauth->userId = $user->id; $oauth->save(); } $userInfo = UserInfo::model()->findByAttributes(array('email' => $samebookUser['email'])); //在oauth表中加sbid if (!$userInfo->oauth->sbid) { $userInfo->oauth->sbid = $samebookUser['userId']; $userInfo->oauth->save(); $userInfo = User::model()->findByAttributes(array('email' => $samebookUser['email'])); } }
public function actionInit() { $model = new InstallInfoForm(); $mailer = new MailerForm(); if (isset($_POST['InstallInfoForm']) && isset($_POST['MailerForm'])) { $model->attributes = $_POST['InstallInfoForm']; $siteForm = new SiteForm(); $siteForm->name = $model->name; $siteForm->subTitle = $model->subTitle; $siteForm->saveSetting(); $user = new User(); $user->email = $model->adminEmail; $user->setPlainPassword($model->adminPassword); $user->save(); $userInfo = new UserInfo(); $userInfo->name = $model->adminName; $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $userInfo->bio = $model->adminBio; $userInfo->isAdmin = 1; // $userInfo->roles = "superAdmin,admin,teacher"; $userInfo->status = "ok"; $userInfo->addTime = time(); $userInfo->introduction = "admin"; $mailer->attributes = $_POST['MailerForm']; if ($userInfo->save() && $mailer->saveSetting()) { $auth = Yii::app()->authManager; $auth->createRole('admin'); $auth->createRole('teacher'); $userInfo->roles = array('admin', 'teacher'); $this->setNav(); $this->setCarousel(); Yii::app()->user->setFlash('success', '系统初始化成功!'); $this->redirect(array('finish')); } } $this->render('init', array('model' => $model, 'mailer' => $mailer)); }
public function postRegister() { $input = Input::only('username', 'email', 'password', 'confirm_password', 'g-recaptcha-response'); $validator_error_messages = ['g-recaptcha-response.required' => 'reCAPTCHA verification is required.']; $validator = Validator::make($input, array('username' => 'required|alpha_dash|unique:users', 'email' => 'required|email|unique:users', 'password' => 'required|min:8', 'confirm_password' => 'required|same:password', 'g-recaptcha-response' => 'required|recaptcha'), $validator_error_messages); if ($validator->fails()) { return Redirect::action('UserController@getRegister')->withErrors($validator)->withInput(); } $user = new User(); $confirmation = str_random(64); $user->username = $input['username']; $user->email = $input['email']; $user->password = Hash::make($input['password']); $user->is_active = 1; $user->register_ip = Request::getClientIp(); $user->last_ip = Request::getClientIp(); $user->confirmation = $confirmation; if ($user->save()) { $user_info = new UserInfo(); $user_info->user_id = $user->id; $user->last_ip = Request::getClientIp(); $user_info->save(); Mail::send('emails.auth.confirmation', array('confirmation' => $confirmation), function ($message) use($input) { $message->from('*****@*****.**', 'Modpack Index'); $message->to($input['email'], $input['username'])->subject('Confirmation for ' . $input['username']); }); return View::make('user.register_success', ['email' => $user->email]); } return Redirect::action('UserController@getRegister')->withErrors(['Error' => 'Unable to create account'])->withInput(); }
/** *添加一个用户 */ public function addUser($email, $password, $info = array()) { $user = new User(); $user->plainPassword = $password; $user->email = $email; //用户名不可缺少 if ($user->save()) { $userInfo = new UserInfo(); $userInfo->id = $user->getPrimaryKey(); $userInfo->email = $user->email; $attributes = $userInfo->getAttributes(); foreach ($info as $k => $v) { if (in_array($k, $attributes)) { $userInfo->{$k} = $v; } } $userInfo->addTime = time(); if ($userInfo->save()) { return true; } else { $user->delete(); } } return false; }
/** * Displays the login page */ public function actionInformation($id = -1) { if ($id == -1) { $user = User::model()->findByAttributes(array('user_name' => Yii::app()->user->name)); if (!$user) { $this->redirect(array('/')); } $user_info = UserInfo::model()->findByPk($user->id); if (!$user_info) { $user_info = new UserInfo(); } if (isset($_POST['UserInfo'])) { if (in_array(Yii::app()->user->isAdmin(), [4])) { Yii::app()->user->setFlash('error', '无更改权限'); $this->render('information', array('user_info' => $user_info)); } $user_info->attributes = $_POST['UserInfo']; $user_info->vocational_certificate = $_POST['UserInfo']['vocational_certificate']; foreach ($user_info->attributes as $k => $v) { if (!strlen($v) && !$v) { unset($user_info[$k]); } } $user_info->id = $user->id; $user_info->ip = $_SERVER['REMOTE_ADDR']; if ($user_info->save()) { Yii::app()->user->setFlash('success', '更改成功'); } else { Yii::app()->user->setFlash('error', '更改失败'); $this->render('information', array('user_info' => $user_info)); Yii::app()->end(); } } $this->render('information', array('user_info' => $user_info)); } else { if (Yii::app()->user->isAdmin() == 0) { $this->redirect(array('/site/index')); } $user_info = UserInfo::model()->findByPk($id); $this->render('information', array('user_info' => $user_info)); } }
/** * [Persist a User] * @param User $user [description] * @return [type] [description] */ public function save(UserInfo $user) { return $user->save(); }
public function actionRegister() { $model = new User(); $model->username = ""; $model->password = ""; $infoModel = new UserInfo(); $infoModel->user_id = $model->id; // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); $error = ''; $form = 'user-Register-form'; //If a new User has been successfully created e.g. the user has created an account from the register.php page if (isset($_POST['User']) && isset($_POST['UserInfo'])) { /*if ($this->actionVerifyRegistration() != "") { $this->render('create', array('model'=>$model)); }*/ echo "<script>console.log('New User Registered');</script>"; // auto-fill biography information $model->attributes = $_POST['User']; $model->pic_url = '/coplat/images/profileimages/default_pic.jpg'; $model->biography = "Tell us something about yourself..."; $model->activation_chain = $this->genRandomString(10); $model->activated = 1; // hash entered password $pw = $model->password; $hasher = new PasswordHash(8, false); $model->password = $hasher->HashPassword($model->password); $error1 = $this->verifyRegistration(); if ($error1 == null) { $model->save(false); if (isset($_POST['UserInfo'])) { // get entered personal info $infoModel->attributes = $_POST['UserInfo']; $infoModel->user_id = $model->id; $infoModel->save(false); } //newUserLogin($model, $pw); $login = new LoginForm(); $login->username = $model->username; $login->password = $pw; $login->login(); $this->redirect("/coplat/index.php/application/portal"); } } $this->render('register', array('model' => $model, 'infoModel' => $infoModel, 'error' => $error)); return; }