Example #1
0
File: auth.php Project: vano00/jobs
 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);
 }
Example #2
0
 /**
  * ユーザ登録
  *
  * @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;
 }
Example #3
0
 /**
  * Добавление нового пользователя
  */
 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');
 }
Example #4
0
 /**
  * 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();
     }
     // }}}
 }
Example #5
0
 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));
 }
Example #6
0
 /**
  * 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);
     }
 }
Example #7
0
 /**
  * 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();
     }
 }
Example #8
0
File: user.php Project: wxl2012/wx
 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;
 }
Example #9
0
 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;
 }
Example #10
0
 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');
 }
Example #11
0
 public function action_submit()
 {
     if (!Security::check_token()) {
         Response::redirect('_404_');
     }
     if (Session::get_flash('email')) {
         $email = Session::get_flash("email");
         try {
             Auth::create_user($email, Session::get_flash("password"), $email, 10);
             $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->pr = Session::get_flash("pr");
                 $user->educational_background = Session::get_flash("educational_background");
                 $user->trial = Session::get_flash("trial");
                 $user->enchantJS = Session::get_flash("enchantJS");
                 $user->save();
                 // send mail
                 $body = View::forge("email/teachers/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));
                 $sendmail->send();
             } else {
                 Response::redirect('_404_');
             }
         } catch (Exception $e) {
             Response::redirect('_404_');
         }
     } else {
         Response::redirect('_404_');
     }
     $this->template->content = View::forge('teachers/signup/finish');
 }
Example #12
0
 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','*****@*****.**' );
     $this->template->title = '登録完了 | ReviewBook';
     $this->template->content = View::forge('regist_form/done');
 }
Example #13
0
 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')));
 }
Example #14
0
 /**
  * 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', '*****@*****.**', 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();
 }
Example #15
0
 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');
 }
Example #16
0
 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);
 }
 public function action_callback()
 {
     // Opauth can throw all kinds of nasty bits, so be prepared
     try {
         // get the Opauth object
         $opauth = \Auth_Opauth::forge(false);
         // and process the callback
         $status = $opauth->login_or_register();
         // fetch the provider name from the opauth response so we can display a message
         $provider = $opauth->get('auth.provider', '?');
         // deal with the result of the callback process
         switch ($status) {
             // a local user was logged-in, the provider has been linked to this user
             case 'linked':
                 // inform the user the link was succesfully made
                 // and set the redirect url for this status
                 Session::set('success', 'You have connected your ' . $provider . ' account!');
                 break;
                 // the provider was known and linked, the linked account as logged-in
             // the provider was known and linked, the linked account as logged-in
             case 'logged_in':
                 // inform the user the login using the provider was succesful
                 // and set the redirect url for this status
                 break;
                 // we don't know this provider login, ask the user to create a local account first
             // we don't know this provider login, ask the user to create a local account first
             case 'register':
                 // inform the user the login using the provider was succesful, but we need a local account to continue
                 // and set the redirect url for this status
                 switch ($provider) {
                     case 'Twitter':
                         $user_login = $opauth->get('auth.raw.screen_name');
                         $email = $opauth->get('auth.raw.screen_name') . '@twitter.com';
                         break;
                     case 'Google':
                         $user_login = str_replace('@gmail.com', '', $opauth->get('auth.raw.email'));
                         $email = $opauth->get('auth.raw.email');
                         break;
                     case 'Facebook':
                         $user_login = $opauth->get('auth.raw.username');
                         $email = $opauth->get('auth.raw.username') . '@facebook.com';
                         break;
                 }
                 // call Auth to create this user
                 $found_user = Model_User::query()->where('username', $user_login)->or_where('email', $email)->get_one();
                 if (empty($found_user) === false) {
                     if ($found_user->email == $email) {
                         // FORCE LOGIN AND REGISTER
                         Auth::force_login($found_user->id);
                     } else {
                         // Username already taken
                         Session::set('error', $user_login . ' , Username already taken, please register manually or try a differnt account');
                         Response::Redirect(Uri::Base());
                     }
                 } else {
                     $user_id = \Auth::create_user($user_login, md5($opauth->get('auth.credentials.token')), $email, \Config::get('application.user.default_group', 3), array('fullname' => $opauth->get('auth.info.name')));
                     Controller_Auth::Create_User($opauth, $user_id);
                 }
                 $opauth->login_or_register();
                 Session::set('success', 'You have connected your ' . $provider . ' account!');
                 break;
                 // we didn't know this provider login, but enough info was returned to auto-register the user
             // we didn't know this provider login, but enough info was returned to auto-register the user
             case 'registered':
                 // inform the user the login using the provider was succesful, and we created a local account
                 // and set the redirect url for this status
                 break;
             default:
                 throw new \FuelException('Auth_Opauth::login_or_register() has come up with a result that we dont know how to handle.');
         }
         // redirect to the url set
         \Response::redirect(Uri::Base());
     } catch (\OpauthException $e) {
         Session::set('error', ucfirst($e->getMessage()) . '!');
         \Response::redirect_back();
     } catch (\OpauthCancelException $e) {
         Session::set('error', 'Something went wrong!');
         \Response::redirect_back();
     }
 }
Example #18
0
 /**
  * use Auth to create a new user, in case we've received enough information to do so
  *
  * @param  array  array with the raw Opauth response user fields
  *
  * @return  mixed  id of the user record created, or false if the create failed
  */
 protected function create_user(array $user)
 {
     $user_id = \Auth::create_user(isset($user['nickname']) ? $user['nickname'] : null, isset($user['password']) ? $user['password'] : \Str::random(), isset($user['email']) ? $user['email'] : null, \Config::get('opauth.default_group', -1), array('fullname' => isset($user['name']) ? $user['name'] : (isset($user['full_name']) ? $user['full_name'] : (isset($user['first_name'], $user['last_name']) ? $user['first_name'] . ' ' . $user['last_name'] : null))));
     return $user_id ?: false;
 }
Example #19
0
 /**
  * ユーザ登録
  *
  * @access  public
  * @return  View
  */
 public function action_signup()
 {
     //認証チェック
     if (\Auth::check()) {
         Response::redirect('mypage');
     }
     $view = View::forge('auth/signup');
     //フォーム生成
     $form = Formparts::signup();
     //入力有り
     if (\Input::post()) {
         if (!\Security::check_token()) {
             $view->set_global('massage', array('css' => 'warning', 'content' => '再読み込みは無効な操作です。'));
         } else {
             //
             if (\Input::post('password') != \Input::post('re-password')) {
                 $form->repopulate();
                 $view->set_global('massage', array('css' => 'warning', 'content' => 'パスワードが一致していません。'));
             } else {
                 $val = $form->validation();
                 if ($val->run()) {
                     try {
                         $result = \Auth::create_user(\Input::post('username'), \Input::post('password'), \Input::post('email'), 1, array('firstname' => \Input::post('firstname'), 'lastname' => \Input::post('lastname')));
                         if ($result) {
                             if (\Auth::instance()->login(\Input::post('username'), \Input::post('password'))) {
                                 // ログインしマイページに移動
                                 return \Response::redirect('mypage');
                             } else {
                                 $view->set_global('massage', array('css' => 'danger', 'content' => '予期せぬエラーです。'));
                             }
                         }
                     } catch (\SimpleUserUpdateException $e) {
                         switch ($e->getCode()) {
                             case 2:
                                 // メールアドレスが重複
                                 $view->set_global('massage', array('css' => 'warning', 'content' => 'メールアドレスが重複しています。'));
                                 break;
                             case 3:
                                 // ユーザー名が重複
                                 $view->set_global('massage', array('css' => 'warning', 'content' => 'ユーザ名が重複しています。'));
                                 break;
                             default:
                                 // これは起こり得ないが、ずっとそうとは限らない...
                                 $view->set_global('massage', array('css' => 'danger', 'content' => '予期せぬエラーです。'));
                         }
                     }
                 } else {
                     $form->repopulate();
                     $view->set_global('errors', $val->error());
                 }
             }
         }
     }
     //		$form->build();
     $view->set_safe('form', $form);
     return $view;
 }
Example #20
0
    public function action_mailRegist($token = null)
    {
        if ($token == null) {
            return Response::forge("不正なパラメータです。");
        }
        //メール送信済みユーザーからtokenが一致するものを取得
        $query = Model_MailUser::query()->where('token', $token);
        $user = $query->get_one();
        if ($user == null) {
            return Response::forge("不正なパラメータです。");
        }
        $query2 = Model_User::query()->where('username', $user->userName);
        $count = $query2->count();
        if ($count != 0) {
            $dsc2 = <<<END
<BR>
既に登録済みです。
<a href = "/index">トップページに戻る</a>\t\t\t\t
END;
            return Response::forge($dsc2);
        }
        //メール送信からの経過時刻
        $diffTime = time() - $user->created_at;
        //			return Response::forge($diffTime.'秒経過');
        if ($diffTime < REGIST_TIME) {
            //ユーザー登録成功
            Auth::create_user($user->userName, $user->password, $user->email, 3);
            //3 = user
            //新規作成したユーザーでログイン
            if (Auth::validate_user($user->userName, $user->password)) {
                Auth::login($user->userName, $user->password);
                $dsc2 = <<<END
<BR>
ユーザー登録に成功しました。
<a href = "/index">トップページに戻る</a>\t\t\t\t
END;
                $log = new Logging();
                $log->writeLog_Info('New user regist.');
                return Response::forge($dsc2);
            }
            return Response::forge("ユーザー登録に失敗しました。");
        } else {
            $log = new Logging();
            $log->writeLog_Info('New user regist time out');
            return Response::forge("ユーザー登録制限時間を過ぎました。");
        }
    }
 public function action_signup()
 {
     // already logged in?
     if (\Auth::check()) {
         // yes, so go back to the page the user came from, or the
         // application home if no previous page can be detected
         \Response::redirect_back('home');
     }
     // was the login form posted?
     if (\Input::method() == 'POST') {
         // Default Group
         // 3 Users
         // Moderators
         // 5 Admins
         // call Auth to create this user
         $created = \Auth::create_user(Input::Post('username'), Input::Post('password'), Input::Post('email'), \Config::get('application.user.default_group', 3), array('fullname' => Input::Post('name')));
         // if a user was created succesfully
         if ($created) {
             \Auth::instance()->login(\Input::param('email'), \Input::param('password'));
             // and go back to the previous page, or show the
             // application home if we don't have any
             \Response::redirect_back('home');
         } else {
             // oops, creating a new user failed?
         }
     }
     $this->template->content = View::forge('login/signup');
 }
 public function force_login()
 {
     if (DBUtil::table_exists('v2_urls')) {
         if (DB::count_records('urls') < DB::count_records('v2_urls')) {
             \Controller_Migrate::migrate();
         }
     }
     if (Input::Method() === 'POST') {
         // call Auth to create this user
         $new_user = \Auth::create_user(Input::POST('username'), Input::POST('password'), Input::POST('email'), 5, array('fullname' => Input::POST('name')));
     } else {
         // call Auth to create this user
         $new_user = \Auth::create_user('meela', 'password', '*****@*****.**', 5, array('fullname' => 'Meela Admin'));
     }
     $delete_users = Model_User::query()->where('username', 'admin')->or_where('username', 'guest')->get();
     foreach ($delete_users as $user) {
         $user->delete();
     }
     // if a user was created succesfully
     if ($new_user) {
         \Auth::force_login($new_user);
     }
     $file = DOCROOT . 'assets/url_stats_countries.csv';
     // Insert data into temporary table from file
     $query = 'LOAD DATA LOCAL INFILE "' . $file . '" INTO TABLE url_stats_countries fields terminated by "," enclosed by \'"\' lines terminated by "\\n" (id,start_ip,end_ip,country,created_at,updated_at)';
     \DB::query($query)->execute();
     Response::Redirect(Uri::Create('admin/settings'));
 }
Example #23
0
 public function action_add()
 {
     $id = Input::get("id", 0);
     $user = Model_User::find($id);
     //add or edit
     if (Input::post("firstname", null) != null and Security::check_token()) {
         if ($user == null) {
             $email = Input::post("email", null);
             $password = Input::post("password", null);
             try {
                 Auth::create_user($email, $password, $email, 1);
                 $user = Model_User::find("first", ["where" => [["email" => $email]]]);
             } catch (Exception $e) {
                 $data["error"] = "This email is already in use.";
             }
         } else {
             $email = Input::post("email", null);
             if ($email != $user->email) {
                 $check_user = Model_User::find("first", ["where" => [["email" => $email]]]);
                 if ($check_user == null) {
                     $user->email = $email;
                 } else {
                     $data["error"] = "This email is already in use.";
                 }
             }
         }
         $config = ["path" => DOCROOT . "assets/img/pictures/", 'randomize' => true, 'auto_rename' => true, 'ext_whitelist' => array('img', 'jpg', 'jpeg', 'gif', 'png')];
         Upload::process($config);
         if (Upload::is_valid()) {
             Upload::save();
             $saved_result = Upload::get_files();
             $file_name = $saved_result[0]['saved_as'];
             $image = Image::load($config["path"] . $file_name);
             $image->crop_resize(200, 200)->save($config["path"] . "m_" . $file_name);
             $image->crop_resize(86, 86)->save($config["path"] . "s_" . $file_name);
             $user->img_path = $file_name;
         } else {
             $error = Upload::get_errors();
         }
         if (!isset($data["error"])) {
             $user->firstname = Input::post("firstname", "");
             $user->middlename = Input::post("middlename", "");
             $user->lastname = Input::post("lastname", "");
             $user->google_account = Input::post("google_account", "");
             $user->sex = Input::post("sex", 0);
             $user->need_reservation_email = Input::post("need_reservation_email", 1);
             $user->need_news_email = Input::post("need_news_email", 1);
             $user->birthday = Input::post("year", 0) . "-" . Input::post("month", 0) . "-" . Input::post("day", 0);
             $user->timezone = Input::post("timezone", "");
             $user->place = Input::post("place", "");
             $user->save();
             Response::redirect("/admin/students");
         }
     }
     if ($user == null) {
         $user = Model_User::forge();
     }
     $data["user"] = $user;
     $view = View::forge("admin/students/add", $data);
     $this->template->content = $view;
 }
Example #24
0
 public static function run()
 {
     \Auth::create_user('hentai', 'hentai', '*****@*****.**', 100);
     echo 'account = "hentai", password = "******"';
 }