本文整理汇总了PHP中Auth::create_user方法的典型用法代码示例。如果您正苦于以下问题:PHP Auth::create_user方法的具体用法?PHP Auth::create_user怎么用?PHP Auth::create_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Auth
的用法示例。
在下文中一共展示了Auth::create_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_create_account
public function action_create_account()
{
if (\Input::post()) {
$user = \Input::post();
$val = \Validation::forge();
$val->add_field('fullname', 'fullname', 'required');
$val->add_field('username', 'username', 'required');
$val->add_field('password', 'password', 'required|min_length[3]|max_length[10]');
$val->add_field('email', 'email', 'required|valid_email');
if ($val->run()) {
try {
\Auth::create_user($user['username'], $user['password'], $user['email'], 1, array('fullname' => $user['fullname']));
} catch (\SimpleUserUpdateException $e) {
\Session::set_flash('error', 'An account with this email address already exist');
\Response::redirect('auth');
}
\Session::set_flash('success', 'The account has been successfully created');
\Response::redirect('/');
} else {
// repopulate the username field and give some error text back to the view.
$data['fullname'] = $user['fullname'];
$data['username'] = $user['username'];
$data['email'] = $user['email'];
\Session::set_flash('error', $val->error());
}
}
$data['actions'] = ['back' => ['label' => 'Back', 'url' => 'auth']];
$this->template->title = "Create an account";
$this->template->content = \View::forge('user/create.twig', $data);
}
示例2: action_regist
/**
* ユーザ登録
*
* @access public
* @return View
*/
public function action_regist()
{
$view = View::forge('admin/regist');
$form = Fieldset::forge();
$form->form()->set_attribute('class', 'form form-horizontal');
$form->add('username', 'ログインID', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 50);
$form->add('password', 'パスワード', array('class' => 'form-control'))->add_rule('required')->add_rule('min_length', 3)->add_rule('max_length', 20);
$form->add('email', 'Eメール', array('class' => 'form-control'))->add_rule('required')->add_rule('valid_email');
$form->add('submit', '', array('type' => 'submit', 'value' => '登録', 'class' => 'btn btn-primary'));
if (\Input::post()) {
$val = $form->validation();
if ($val->run()) {
$result = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), 1, array());
if ($result) {
$view->set_global('massage', array('css' => 'success', 'content' => '登録に成功しました。'));
} else {
$form->repopulate();
$view->set_global('massage', array('css' => 'danger', 'content' => '既に登録済みの情報が使用されています。'));
}
} else {
$form->repopulate();
$view->set_global('errors', $val->error());
}
}
$form->build('/form/confirm');
$view->set_safe('form', $form);
return $view;
}
示例3: action_create
/**
* Добавление нового пользователя
*/
public function action_create()
{
if (\Input::method() == 'POST') {
$val = \Model_User::validate('create');
if ($val->run()) {
try {
$created = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), \Config::get('application.user.default_group', 100));
if ($created) {
\Session::set_flash('success', e('Добавлен новый пользователь'));
\Response::redirect_back('admin/users');
} else {
// oops, creating a new user failed?
\Session::set_flash('error', e('Не удалось создать пользователя'));
}
} catch (\SimpleUserUpdateException $e) {
// Повтор е-мэил
if ($e->getCode() == 2) {
\Session::set_flash('error', e('E-Mail существует'));
} elseif ($e->getCode() == 3) {
\Session::set_flash('error', e('Логин существует'));
} else {
\Messages::error($e->getMessage());
}
}
} else {
\Session::set_flash('error', $val->error());
}
}
$this->template->title = 'Пользователи';
$this->template->content = \View::forge('users/create');
}
示例4: index
/**
* This method gets ran when a valid method name is not used in the command.
*
* Usage (from command line):
*
* php oil r setuptables:index "arguments"
*
* @return string
*/
public function index($args = NULL)
{
echo "\n===========================================";
echo "\nRunning task [Setuptables:Index]";
echo "\n-------------------------------------------\n\n";
/***************************
Put in TASK DETAILS HERE
**************************/
// 初期ユーザー定義
$init_users = array(array('name' => 'codex', 'password' => '1234', 'group' => 6));
// データベース接続
\DBUtil::set_connection(null);
// {{{ トランケート
$truncates = array('', '_permissions', '_metadata', '_user_permissions', '_group_permissions', '_role_permissions');
foreach ($truncates as $truncate) {
\DBUtil::truncate_table('users' . $truncate);
}
// }}}
// {{{ 初期ユーザー追加
foreach ($init_users as $init_user) {
// ユーザー名
$key = $init_user['name'];
// パスワード
$password = $init_user['password'];
// メールアドレス
$email = $key . '@xenophy.com';
// グループ
$group = $init_user['group'];
// 追加
$user = \Auth\Model\Auth_User::forge()->find(\Auth::create_user($key, $password, $email, $group));
// 保存
$user->save();
}
// }}}
}
示例5: action_registration
public function action_registration()
{
if ($this->is_logged) {
die(json_encode(['status' => 'error', 'message' => 'You olready registered'], JSON_UNESCAPED_UNICODE));
}
$lUsername = Input::post('username', null);
$lPassword = Input::post('password', null);
$lPassword2 = Input::post('password2', null);
$lEmail = Input::post('email', null);
if (empty($lUsername) || empty($lPassword) || empty($lPassword2) || empty($lEmail)) {
$lError = 'Missing params';
}
if ($lPassword !== $lPassword2) {
$lError = DifferentFunc::translation('passwords_mismatch');
}
if (!empty($lError)) {
die(json_encode(['status' => 'error', 'message' => $lError], JSON_UNESCAPED_UNICODE));
}
try {
Auth::create_user($lUsername, $lPassword, $lEmail, 1, ['role_id' => AuthModule::UR_USER]);
Auth::login($lUsername, $lPassword);
} catch (Exception $e) {
$lError = $e->getMessage();
die(json_encode(['status' => 'error', 'message' => $lError], JSON_UNESCAPED_UNICODE));
}
die(json_encode(['status' => 'ok'], JSON_UNESCAPED_UNICODE));
}
示例6: create
/**
* Usage (from command line):
*
* php oil r user:create email password name
*
* @return string
*/
public static function create($email, $password, $name)
{
try {
if (!\Auth::create_user($email, $password, $name)) {
throw new \FuelException('Failed to create user.');
}
return \Util_Task::output_message('Create site user ' . $name . '.');
} catch (\FuelException $e) {
return \Util_Task::output_message(sprintf('createuser error: %s', $e->getMessage()), false);
}
}
示例7: run
/**
* Usage (from command line):
*
* php oil r admin::createuser username password email group
*
* @return string
*/
public static function run($username, $password, $email, $group = 1)
{
try {
if (!\Auth::create_user($username, $password, $email, $group)) {
throw new \FuelException('Failed to create user.');
}
return 'Create admin user ' . $username . '.';
} catch (\FuelException $e) {
return 'admin::createuser error: ' . $e->getMessage();
}
}
示例8: createUser
public static function createUser($data)
{
$user_id = 0;
if (!isset($data['profile_fields'])) {
$data['profile_fields'] = [];
}
try {
$user_id = \Auth::create_user($data['username'], $data['password'], $data['email'], $data['group_id'], $data['profile_fields']);
} catch (SimpleUserUpdateException $e) {
\Log::error('create user error message:' . $e->getMessage() . '; error data:' . json_encode($data));
}
return $user_id;
}
示例9: action_index
public function action_index()
{
//すでにログイン済であればログイン後のページへリダイレクト
Auth::check() and Response::redirect('members/top');
//エラーメッセージ用変数初期化
$error = null;
//signup成功時のメッセージ
$msg = null;
//ログイン用のオブジェクト生成
$auth = Auth::instance();
$uname = Input::post('username', null);
$pass = Input::post('password', null);
if (isset($_POST['login'])) {
// login処理
if ($auth->login(Input::post('username'), Input::post('password'))) {
// ログイン成功時、ログイン後のページへリダイレクト
Response::redirect('members/top');
} else {
// ログイン失敗時、エラーメッセージ作成
$error = 'loginに失敗しました。ユーザ名かパスワードに誤りがあります';
}
} elseif (isset($_POST['signup'])) {
// signup処理
$new_uname = $_POST['new_uname'];
$new_pass = $_POST['new_pass'];
try {
$icons = array("default1.jpg", "default2.jpg", "default3.jpg", "default4.jpg");
$count = count($icons);
$random = rand(0, $count - 1);
Auth::create_user($new_uname, $new_pass, $new_uname . "@tabi.com");
Model_Members_General2::setProfile($new_uname, $icons[$random]);
$msg = "signupに成功しました。loginして下さい。";
} catch (Exception $e) {
if ($new_uname != null && $new_pass != null) {
// signup失敗時、エラーメッセージ作成
$error = "signupに失敗しました。nameは半角英数字のみで、重複できません。";
} else {
// signup記入漏れ時、エラーメッセージ作成
$error = "signに失敗しました。入力が不十分です。";
}
}
}
//ビューテンプレートを呼び出し
$view = View::forge('loginsignup');
//エラーメッセージをビューにセット
$view->set('error', $error);
$view->set('msg', $msg);
return $view;
}
示例10: action_submit
public function action_submit()
{
if (!Security::check_token()) {
Response::redirect('_404_');
}
if (Session::get_flash('email')) {
$email = Session::get_flash("email");
Auth::create_user($email, Session::get_flash("password"), $email, 1);
$user = Model_User::find("first", ["where" => [["email", $email]]]);
if ($user != null) {
$user->sex = Session::get_flash("sex");
$user->firstname = Session::get_flash("firstname");
$user->middlename = Session::get_flash("middlename");
$user->lastname = Session::get_flash("lastname");
$user->birthday = Session::get_flash("year") . "-" . Session::get_flash("month") . "-" . Session::get_flash("day");
$user->google_account = Session::get_flash("google_account");
$user->need_reservation_email = Session::get_flash("need_reservation_email");
$user->need_news_email = Session::get_flash("need_news_email");
$user->timezone = Session::get_flash("timezone");
$user->place = Session::get_flash("grameen");
$user->grameen_student = Session::get_flash("grameen_student");
$user->nationality = Session::get_flash("nationality");
$user->save();
// send mail
$body = View::forge("email/students/signup");
$body->set("name", $user->firstname);
$body->set("user", $user);
$body->set("ymd", explode("-", $user->birthday));
$sendmail = Email::forge("JIS");
$sendmail->from(Config::get("statics.info_email"), Config::get("statics.info_name"));
$sendmail->to($user->email);
$sendmail->subject("Welcome Aboard! / Game-BootCamp");
$sendmail->html_body(htmlspecialchars_decode($body));
$documents = Model_Document::query()->where('type', 1)->where('deleted_at', 0)->limit(1)->get_one();
if (count($documents) > 0) {
$query = Model_Document::find($documents->id);
$sendmail->attach(DOCROOT . '/contents/' . $query->path);
}
$sendmail->send();
} else {
Response::redirect('_404_/?hehe');
}
} else {
Response::redirect('_404_');
}
$this->template->content = View::forge('students/signup/finish');
}
示例11: action_done
public function action_done()
{
if (!Security::check_token()) {
throw new HttpInvalidInputException('正しいルートからアクセスしてください。');
}
$val = $this->regist_validation()->add_callable('MyValidationRules');
if (!$val->run()) {
$this->template->title = '入力エラー | ReviewBook';
$this->template->content = View::forge('regist_form/form');
$this->template->content->set_safe('html_error', $val->show_errors());
return;
}
Auth::create_user(Input::post('username'), Input::post('password'), Input::post('email'));
// Auth::create_user( 'test','test123','test@test.com' );
$this->template->title = '登録完了 | ReviewBook';
$this->template->content = View::forge('regist_form/done');
}
示例12: action_register
public function action_register()
{
$user_hash = \Session::get('ninjauth.user');
$authentication = \Session::get('ninjauth.authentication');
$full_name = \Input::post('full_name') ?: \Arr::get($user_hash, 'name');
$username = \Input::post('username') ?: \Arr::get($user_hash, 'nickname');
$email = \Input::post('email') ?: \Arr::get($user_hash, 'email');
$password = \Input::post('password');
if ($username and $full_name and $email and $password) {
try {
$user_id = \Auth::create_user($username, $password, $email, \Config::get('ninjauth.default_group'), array('full_name' => $full_name));
} catch (SimpleUserUpdateException $e) {
\Session::set_flash('ninjauth.error', $e->getMessage());
goto display;
}
if ($user_id) {
Model_Authentication::forge(array('user_id' => $user_id, 'provider' => $authentication['provider'], 'uid' => $authentication['uid'], 'access_token' => $authentication['access_token'], 'secret' => $authentication['secret'], 'refresh_token' => $authentication['refresh_token'], 'expires' => $authentication['expires'], 'created_at' => time()))->save();
}
\Response::redirect(\Config::get('ninjauth.urls.registered'));
}
display:
$this->response->body = \View::forge('register', array('user' => (object) compact('username', 'full_name', 'email', 'password')));
}
示例13: up
/**
* Create tables: users, options, posts, tags, posts_tags
*/
public function up()
{
\DBUtil::create_table('users', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'username' => array('type' => 'varchar', 'constraint' => 50), 'password' => array('type' => 'varchar', 'constraint' => 256), 'group' => array('type' => 'int', 'constraint' => 11, 'default' => 1), 'email' => array('type' => 'varchar', 'constraint' => 256), 'last_login' => array('type' => 'varchar', 'constraint' => 25), 'login_hash' => array('type' => 'varchar', 'constraint' => 256), 'profile_fields' => array('type' => 'text')), array('id'));
// Coming soon
// \DBUtil::create_index('users', 'username', 'unique');
// \DBUtil::create_index('users', 'email', 'unique');
\DBUtil::create_table('options', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'option' => array('type' => 'varchar', 'constraint' => 128), 'value' => array('type' => 'text')), array('id'));
// Coming soon
// \DBUtil::create_index('options', 'option', 'unique');
\DBUtil::create_table('posts', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'user_id' => array('type' => 'int', 'constraint' => 11), 'title' => array('type' => 'varchar', 'constraint' => 128), 'slug' => array('type' => 'varchar', 'constraint' => 128), 'body' => array('type' => 'text'), 'created_at' => array('type' => 'datetime'), 'updated_at' => array('type' => 'datetime')), array('id'));
// Coming soon
// \DBUtil::create_index('posts', 'slug', 'unique');
\DBUtil::create_table('tags', array('id' => array('type' => 'int', 'constraint' => 11, 'auto_increment' => true), 'tag' => array('type' => 'varchar', 'constraint' => 128), 'slug' => array('type' => 'varchar', 'constraint' => 128)), array('id'));
// Coming soon
// \DBUtil::create_index('tags', 'tag', 'unique');
// \DBUtil::create_index('tags', 'slug', 'unique');
\DBUtil::create_table('posts_tags', array('post_id' => array('type' => 'int', 'constraint' => 11), 'tag_id' => array('type' => 'int', 'constraint' => 11)));
\Auth::create_user('admin', 'admin', 'admin@example.com', 100);
\Option::reset();
\DB::insert('posts')->columns(array('user_id', 'title', 'slug', 'body', 'created_at', 'updated_at'))->values(array(1, 'My first post', 'my-first-post', 'This is my first post. Yiharr!', \Date::forge()->format('mysql'), \Date::forge()->format('mysql')))->execute();
\DB::insert('tags')->columns(array('tag', 'slug'))->values(array('My first tag', 'my-first-tag'))->execute();
\DB::insert('posts_tags')->columns(array('post_id', 'tag_id'))->values(array(1, 1))->execute();
}
示例14: action_create
public function action_create()
{
if (Input::method() == 'POST') {
if (Input::post('password')) {
$val = Validation::forge();
$val->add_field('email', 'Email address', 'valid_email')->set_error_message('valid_email', ' Please provide a valid email address.');
$val->add('password', 'Password')->add_rule('required')->add_rule('min_length', 8)->add_rule('max_length', 100)->set_error_message('min_length', ' Password must contain between 8 to 100 characters')->set_error_message('max_length', ' Password must contain between 8 to 100 characters');
if ($val->run()) {
/*
* Validation passed
*/
try {
/*
* Unique serial based off timestamp and rand()
* for user saved in EAV table by FuelPHP
*/
$options = array('new_user' => true, 'subscription' => Input::post('subscription'), 'billing_address', 'billing_address', 'billing_city', 'billing_state', 'billing_zip_code', 'credit_card_number', 'credit_card_csv', 'credit_card_zip_code', 'credit_card_expiration');
if (Input::post('subscription') != 'digital') {
$options = array('delivery_address', 'delivery_address', 'delivery_city', 'delivery_state', 'delivery_zip_code');
}
// $options = array(
// 'subscription' => Input::post('subscription'),
// );
$user = \Auth::create_user(Input::post('username'), Input::post('password'), Input::post('username'), 1, $options);
\Auth::force_login($user);
$email = Input::post('username');
\Messages::success("Created account for {$email}");
/*
* ( Input::referrer() === $main_login_forms or Input::referrer() === $main_registration_forms )
* FIxes loop problem after redirect
*/
$main_login_forms = Uri::base(false) . $this->selfReferrerLogin;
$main_registration_forms = Uri::base(false) . $this->selfReferrerRegistration;
if (Input::referrer() === $main_login_forms or Input::referrer() === $main_registration_forms) {
\Response::redirect('backend/account');
}
\Response::redirect_back();
} catch (Exception $e) {
\Messages::error($e->getMessage());
\Response::redirect_back();
}
} else {
$error = array();
foreach ($val->error() as $field => $error) {
\Messages::error($error->get_message());
// The field Title is required and must contain a value.
}
\Response::redirect_back();
}
} else {
\Messages::error('Please specify a password.');
\Response::redirect_back();
}
}
// display the login page
$this->template->content = View::forge('user/register');
}
示例15: action_register
public function action_register()
{
// create the registration fieldset
$form = \Fieldset::forge('registerform');
// add a csrf token to prevent CSRF attacks
$form->form()->add_csrf();
// and populate the form with the model properties
$form->add_model('Model\\Auth_User');
// add the fullname field, it's a profile property, not a user property
$form->add_after('fullname', __('login.form.fullname'), array(), array(), 'username')->add_rule('required');
// add a password confirmation field
$form->add_after('confirm', __('login.form.confirm'), array('type' => 'password'), array(), 'password')->add_rule('required');
// make sure the password is required
$form->field('password')->add_rule('required');
// and new users are not allowed to select the group they're in (duh!)
$form->disable('group_id');
// since it's not on the form, make sure validation doesn't trip on its absence
$form->field('group_id')->delete_rule('required')->delete_rule('is_numeric');
// fetch the oauth provider from the session (if present)
$provider = \Session::get('auth-strategy.authentication.provider', false);
// if we have provider information, create the login fieldset too
if ($provider) {
// disable the username, it was passed to us by the Oauth strategy
$form->field('username')->set_attribute('readonly', true);
// create an additional login form so we can link providers to existing accounts
$login = \Fieldset::forge('loginform');
$login->form()->add_csrf();
$login->add_model('Model\\Auth_User');
// we only need username and password
$login->disable('group_id')->disable('email');
// since they're not on the form, make sure validation doesn't trip on their absence
$login->field('group_id')->delete_rule('required')->delete_rule('is_numeric');
$login->field('email')->delete_rule('required')->delete_rule('valid_email');
}
// was the registration form posted?
if (\Input::method() == 'POST') {
// was the login form posted?
if ($provider and \Input::post('login')) {
// check the credentials.
if (\Auth::instance()->login(\Input::param('username'), \Input::param('password'))) {
// get the current logged-in user's id
list(, $userid) = \Auth::instance()->get_user_id();
// so we can link it to the provider manually
$this->link_provider($userid);
// logged in, go back where we came from,
// or the the user dashboard if we don't know
\Response::redirect_back('dashboard');
} else {
// login failed, show an error message
Log::error(__('login.failure'));
}
} elseif (\Input::post('register')) {
// validate the input
$form->validation()->run();
// if validated, create the user
if (!$form->validation()->error()) {
try {
// call Auth to create this user
$created = \Auth::create_user($form->validated('username'), $form->validated('password'), $form->validated('email'), \Config::get('application.user.default_group', 1), array('fullname' => $form->validated('fullname')));
// if a user was created succesfully
if ($created) {
// inform the user
// link new user
$this->link_provider($created);
// and go back to the previous page, or show the
// application dashboard if we don't have any
\Response::redirect_back('/');
} else {
// oops, creating a new user failed?
Log::error(__('login.account-creation-failed'));
}
} catch (\SimpleUserUpdateException $e) {
// duplicate email address
if ($e->getCode() == 2) {
Log::error(__('login.email-already-exists'));
} elseif ($e->getCode() == 3) {
Log::error(__('login.username-already-exists'));
} else {
Log::error($e->getMessage());
}
}
}
}
// validation failed, repopulate the form from the posted data
$form->repopulate();
} else {
// get the auth-strategy data from the session (created by the callback)
$user_hash = \Session::get('auth-strategy.user', array());
// populate the registration form with the data from the provider callback
$form->populate(array('username' => \Arr::get($user_hash, 'nickname'), 'fullname' => \Arr::get($user_hash, 'name'), 'email' => \Arr::get($user_hash, 'email')));
}
$form->add('register', '', array('type' => 'hidden', 'value' => '1'));
$form->add('submit', '', array('type' => 'submit', 'value' => 'submit'));
// pass the fieldset to the form, and display the new user registration view
return \View::forge('login/registration')->set('form', $form->build(), false)->set('login', isset($login) ? $login : null, false);
}