Permalink
Browse files

ulogin

  • Loading branch information...
1 parent f378b29 commit 0ae35b4d693b487774313d6ca916a930f8c15b21 @studentIvan committed May 4, 2012
Showing with 42 additions and 0 deletions.
  1. +42 −0 helpers/ULogin.php
View
@@ -0,0 +1,42 @@
+<?php
+class ULogin
+{
+ /**
+ * @static
+ * @param string $token
+ * @return array
+ */
+ public static function getData($token) {
+ $s = file_get_contents('http://ulogin.ru/token.php?token=' . $token . '&host=' . $_SERVER['HTTP_HOST']);
+ return json_decode($s, true);
+ }
+
+ /**
+ * @static
+ *
+ */
+ public static function initSession() {
+ Process::$context['user'] = Session::getAllStorageData();
+ }
+
+ /**
+ * @static
+ * @return bool
+ */
+ public static function authorize()
+ {
+ if ($token = Data::input('token')) {
+ $userData = self::getData($token);
+ if (isset($userData['first_name']) and isset($userData['last_name'])) {
+ foreach ($userData as $key => $value) {
+ Session::setStorageData($key, $value);
+ }
+ return true;
+ } else {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ }
+}

0 comments on commit 0ae35b4

Please sign in to comment.