/**
  * The authenticate action has to be triggered through an HTTP POST Request, only if the user agent
  * comes directly from the index (login form) action.
  *
  * @param string $username The username provided through the login form.
  * @param string $password The password provided through the login form.
  * @param string $ref The action where the user-agent has to be redirect if the authentication process is a success.
  */
 public function authenticate($username, $password, $ref, $openid)
 {
     if (!empty($openid)) {
         $oid = new Openid();
         $oid->try_auth($openid);
         exit;
     }
     Auth::login($username, $password);
     if (Auth::isAuth()) {
         // Authentication process succeeded.
         // We log the connection if necessary.
         // FIXME Use a real log library to log messages.
         if (LOGS_USERS) {
             $this->logConnection();
         }
         // Redirection in the portal.
         DefaultFC::redirection($ref);
         exit;
     } else {
         # log user to the anonymous account
         //$_SESSION['isError'] = true;
         //$_SESSION['message'] = __("Wrong login or password. Please try again.");
         Auth::login('anonymous', 'anonymous');
         DefaultFC::redirection('wall/index');
         DefaultFC::redirection('users/index');
         exit;
     }
 }
Beispiel #2
0
 public function index()
 {
     $openid = new Openid();
     $data = array();
     try {
         $button['small'] = "small";
         $button['large_no'] = "large_noborder";
         $button['large'] = "large_border";
         $button = $button[button_style];
         if (!$openid->mode) {
             if (isset($_GET['login'])) {
                 $openid->identity = 'http://steamcommunity.com/openid';
                 header('Location: ' . $openid->authUrl());
             }
             $data['form'] = "<form action=\"?login\" method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_" . $button . ".png\"></form>";
         } elseif ($openid->mode == 'cancel') {
             echo 'User has canceled authentication!';
         } else {
             if ($openid->validate()) {
                 $id = $openid->identity;
                 $ptn = "/^http:\\/\\/steamcommunity\\.com\\/openid\\/id\\/(7[0-9]{15,25}+)\$/";
                 preg_match($ptn, $id, $matches);
                 $_SESSION['steamid'] = $matches[1];
                 //Determine the return to page. We substract "login&"" to remove the login var from the URL.
                 //"file.php?login&foo=bar" would become "file.php?foo=bar"
                 $returnTo = str_replace('login&', '', $_GET['openid_return_to']);
                 //If it didn't change anything, it means that there's no additionals vars, so remove the login var so that we don't get redirected to Steam over and over.
                 if ($returnTo === $_GET['openid_return_to']) {
                     $returnTo = str_replace('?login', '', $_GET['openid_return_to']);
                 }
                 header('Location: ' . $returnTo);
             } else {
                 $data['form'] = "<form action=" . loginpage . " method=\"post\"> <input type=\"image\" src=\"http://cdn.steamcommunity.com/public/images/signinthroughsteam/sits_" . $button . ".png\"></form>";
             }
         }
     } catch (Exception $e) {
     }
     $this->load->view('csgo', $data);
 }
Beispiel #3
0
 protected static function read_config($item)
 {
     if (!self::$config) {
         self::$config = CI()->config->item('openid', 'extid');
     }
     $conf = null;
     if (isset(self::$config[$item])) {
         $conf = self::$config[$item];
     } elseif (isset(self::$default_config[$item])) {
         $conf = self::$default_config[$item];
     }
     return $conf;
 }
Beispiel #4
0
 /**
  * openid_auth_2
  * Authenticate user with OpenID, step 2
  */
 private static function openid_auth_2()
 {
     $results = array();
     $results['type'] = 'openid';
     $consumer = Openid::get_consumer();
     if ($consumer) {
         $response = $consumer->complete(Openid::get_return_url());
         if ($response->status == Auth_OpenID_CANCEL) {
             $results['success'] = false;
             $results['error'] = 'OpenID verification cancelled.';
         } else {
             if ($response->status == Auth_OpenID_FAILURE) {
                 $results['success'] = false;
                 $results['error'] = 'OpenID authentication failed: ' . $response->message;
             } else {
                 if ($response->status == Auth_OpenID_SUCCESS) {
                     // Extract the identity URL and Simple Registration data (if it was returned).
                     $sreg_resp = Auth_OpenID_SRegResponse::fromSuccessResponse($response);
                     $sreg = $sreg_resp->contents();
                     $results['website'] = $response->getDisplayIdentifier();
                     if (@$sreg['email']) {
                         $results['email'] = $sreg['email'];
                     }
                     if (@$sreg['nickname']) {
                         $results['username'] = $sreg['nickname'];
                     }
                     if (@$sreg['fullname']) {
                         $results['name'] = $sreg['fullname'];
                     }
                     $users = User::get_from_website($results['website']);
                     if (count($users) > 0) {
                         if (count($users) == 1) {
                             $user = new User($users[0]);
                             $results['success'] = true;
                             $results['username'] = $user->username;
                         } else {
                             // Several users for the same website/openid? Allowed but stupid, try to get a match on username.
                             // Should we make website field unique?
                             foreach ($users as $id) {
                                 $user = new User($id);
                                 if ($user->username == $results['username']) {
                                     $results['success'] = true;
                                     $results['username'] = $user->username;
                                 }
                             }
                         }
                     } else {
                         // Don't return success if an user already exists for this username but don't have this openid identity as website
                         $user = User::get_from_username($results['username']);
                         if ($user->id) {
                             $results['success'] = false;
                             $results['error'] = 'No user associated to this OpenID and username already taken.';
                         } else {
                             $results['success'] = true;
                             $results['error'] = 'No user associated to this OpenID.';
                         }
                     }
                 }
             }
         }
     }
     return $results;
 }
Beispiel #5
0
 public function push_openids()
 {
     $url = "https://api.weixin.qq.com/cgi-bin/message/send?access_token=" . $this->token;
     $news = ['articles' => [['title' => '联想服务周末加班,坚持为您升Win10', 'description' => '联想服务周末加班,坚持为您升Win10', 'url' => 'http://mp.weixin.qq.com/s?__biz=MjM5MjAyNzE4MA==&mid=280755695&idx=1&sn=b6425132cf991476e6e8fdd2551e19a6#rd', 'picurl' => 'http://mmbiz.qpic.cn/mmbiz/K1QTs69PnJTPX01VHWKbPibeESz4uatMdcXbUBlVTqNe0FbbVO81kMlaTgo92KN2piaVLAp797iat8hDm50651m8A/640?wx_fmt=jpeg&wxfrom=5&wx_lazy=1']]];
     $page = 1;
     $pagesize = 10000;
     $size = ($page - 1) * $pagesize;
     $openids = Openid::skip(1500)->take(8500)->get()->toArray();
     foreach ($openids as $k => $v) {
         $data = ['touser' => $v['openid'], 'msgtype' => 'news', 'news' => $news];
         $data = json_encode($data, JSON_UNESCAPED_UNICODE);
         $result = $this->sendPost($url, $data);
         var_dump($v['id'] . $result);
     }
 }