コード例 #1
0
ファイル: account.php プロジェクト: wxl2012/wx
 /**
  * 根据微信推送的包,创建相关帐户信息
  *
  * @param $openid 微信服务器推送的微信粉丝OpenId
  * @param $account 接受微信服务器推送数据的公众号实体对象
  * @return 创建成功返回微信OpenId数据对象,否则返回False
  */
 public static function createWechatAccount($openid, $account = [])
 {
     //创建微信信息
     $wechat = \Model_Wechat::forge(['nickname' => $openid]);
     //是否创建用户登录信息
     if (isset($account->is_subscribe_create_user) && $account->is_subscribe_create_user) {
         $params = ['username' => "wx_{$openid}", 'password' => "w{$account->id}#{$openid}", 'email' => "wx_{$openid}@{$account->id}.com", 'group_id' => $account->create_user_default_group];
         $user_id = \Model_User::createUser($params);
         $wechat->user_id = $user_id;
         $params = ['user_id' => $user_id];
         $people = \Model_People::forge($params);
         $people->save();
         //是否创建会员信息
         if (isset($account->is_subscribe_create_member) && $account->is_subscribe_create_member) {
             $params = ['no' => "{$account->seller_id}{$wechat->user_id}" . time(), 'user_id' => $wechat->user_id];
             $member = \Model_Member::forge($params);
             $member->save();
         }
     }
     //创建微信OpenID记录
     $params = ['openid' => $openid, 'account_id' => $account->id];
     $wechatOpenid = \Model_WechatOpenid::forge($params);
     $wechat->ids = [$wechatOpenid];
     $wechat->save();
     return $wechatOpenid;
 }
コード例 #2
0
ファイル: uzuraauth.php プロジェクト: uzura8/flockbird
 /**
  * Create new user
  *
  * @param   string  must contain valid email address
  * @param   string
  * @param   string
  * @param   int     group id: now unuse.
  * @param   Array: now unuse.
  * @return  bool
  */
 public function create_user($email, $password, $name = '', $group = 1, array $profile_fields = array())
 {
     // prep the password
     $password = trim($password);
     // and validate the email address
     $email = filter_var(trim($email), FILTER_VALIDATE_EMAIL);
     // bail out if we're missing username, password or email address
     if (empty($password) or empty($email)) {
         throw new \SimpleUserUpdateException('Email address or password is not given, or email address is invalid', 1);
     }
     // check if we already have an account with this email address or username
     $duplicate = \Model_MemberAuth::query()->where('email', $email)->get_one();
     // did we find one?
     if ($duplicate) {
         // bail out with an exception
         if (strtolower($email) == strtolower($duplicate->email)) {
             throw new \SimpleUserUpdateException('Email address already exists', 2);
         }
     }
     // do we have a logged-in user?
     if ($currentuser = \Auth::get_user_id()) {
         $currentuser = $currentuser[1];
     } else {
         $currentuser = 0;
     }
     // create the new user record
     try {
         $member = \Model_Member::forge();
         if (strlen($name)) {
             $member->name = $name;
         }
         $member->register_type = 0;
         $member->filesize_total = 0;
         $member->sex_public_flag = 0;
         $member->birthyear_public_flag = 0;
         $member->birthday_public_flag = 0;
         $member->invite_member_id = 0;
         $result = $member->save();
         $member_auth = \Model_MemberAuth::forge();
         $member_auth->member_id = $member->id;
         $member_auth->email = $email;
         $member_auth->password = $this->hash_password((string) $password, $email);
         $result = $member_auth->save() && $result;
     } catch (\Exception $e) {
         $result = false;
     }
     $this->member = $member;
     // and the id of the created user, or false if creation failed
     return $result ? $member->id : false;
 }
コード例 #3
0
ファイル: auth.php プロジェクト: uzura8/flockbird
 public function provider_signup($provider, $response = null)
 {
     $service_name = isset($response['auth']['info']['name']) ? $response['auth']['info']['name'] : $response['auth']['info']['nickname'];
     $input = array('uid' => (string) $response['auth']['uid'], 'token' => $response['auth']['credentials']['token'], 'service_name' => $response['auth']['info']['name']);
     if (!empty($response['auth']['credentials']['expires'])) {
         $input['expires'] = strtotime($response['auth']['credentials']['expires']);
     }
     if ($service_url = $this->get_service_url($provider, $response)) {
         $input['service_url'] = $service_url;
     }
     try {
         $member_oauth = Model_MemberOauth::forge();
         $val = Validation::forge('provider_signup');
         $val->add_model($member_oauth);
         $val->fieldset()->field('member_id')->delete_rule('required');
         if (!$val->run($input)) {
             throw new \FuelException($val->show_errors());
         }
         $input = $val->validated();
         $provider_id = Model_OauthProvider::get_id($provider);
         \DB::start_transaction();
         $member = Model_Member::forge();
         $member->name = str_replace(' ', '', $input['service_name']);
         list($member->sex, $member->sex_public_flag) = Site_Oauth::get_sex($response, $provider);
         list($member->birthyear, $member->birthyear_public_flag) = Site_Oauth::get_birthyear($response, $provider);
         list($member->birthday, $member->birthday_public_flag) = Site_Oauth::get_birthday($response, $provider);
         $member->filesize_total = 0;
         $member->register_type = $provider_id;
         if ($member->save() === false) {
             throw new \FuelException('Member save failed.');
         }
         $member_oauth->member_id = $member->id;
         $member_oauth->oauth_provider_id = $provider_id;
         $member_oauth->uid = $input['uid'];
         $member_oauth->token = $input['token'];
         $member_oauth->secret = $input['secret'];
         $member_oauth->service_name = $input['service_name'];
         if (!empty($input['expires'])) {
             $member_oauth->expires = $input['expires'];
         }
         if (!empty($input['service_url'])) {
             $member_oauth->service_url = $input['service_url'];
         }
         if ($member_oauth->save() === false) {
             throw new \FuelException('Oauth data save failed.');
         }
         if (!empty($response['auth']['info']['email'])) {
             Model_Memberauth::save_email($response['auth']['info']['email'], $member->id);
         }
         if (conf('auth.oauth.saveTermsUnAgreement')) {
             Model_MemberConfig::set_value($member->id, 'terms_un_agreement', 1);
         }
         // timeline 投稿
         if (is_enabled('timeline')) {
             \Timeline\Site_Model::save_timeline($member->id, null, 'member_register', $member->id, $member->created_at);
         }
         \DB::commit_transaction();
         if (!empty($response['auth']['info']['image'])) {
             $this->save_profile_image($response['auth']['provider'], $response['auth']['info']['image'], $member);
         }
     } catch (\FuelException $e) {
         if (\DB::in_transaction()) {
             \DB::rollback_transaction();
         }
         if (conf('auth.oauth.log.isOutputErrorLog.provider_signup')) {
             \Util_Toolkit::log_error('OAuth provider_signup error: ' . isset($e) ? $e->getMessage() : '');
         }
         return $this->login_failed();
     }
     $this->force_login($member->id);
     if (conf('auth.oauth.forceSetRememberMe')) {
         Auth::remember_me();
     }
     return $this->login_succeeded();
 }