Example #1
0
        public static MailUserModel GetUser(HttpRequestBase request)
        {
            var model = new MailUserModel {
                IsAutharization = false
            };

            try
            {
                var userCookie = request.Cookies["mail_token"];
                if (userCookie != null)
                {
                    var stream = HttpTools.PostStream(InfoUrl,
                                                      string.Format("oauth_token={0}&client_id={1}&format=json&method=users.getInfo&sig={2}",
                                                                    userCookie.Value, SiteId, ""));
                    model = SerializeTools.Deserialize <MailUserModel>(stream);
                    model.IsAutharization = true;
                }
            }
            catch (Exception ex)
            {
                MonitorLog.WriteLog(ex.InnerException + ex.Message, MonitorLog.typelog.Error, true);
                model.IsAutharization = false;
            }

            return(model);
        }
Example #2
0
        public static string GetAuthorizationCookie(HttpCookieCollection cookies, string code, IBaseDb db)
        {
            //var code = request.QueryString["code"];

            var stream = HttpTools.PostStream("https://oauth.yandex.ru/token",
                                              string.Format("grant_type=authorization_code&code={0}&client_id={1}&client_secret={2}", code, ClientId, Password));

            var model = SerializeTools.Deserialize <TokenModel>(stream);

            var userCookie = new HttpCookie("yandex_token")
            {
                Value   = model.access_token,
                Expires = DateTime.Now.AddDays(30)
            };


            stream = HttpTools.PostStream(InfoUrl, string.Format("oauth_token={0}", userCookie.Value));
            var email = SerializeTools.Deserialize <UserModel>(stream).default_email;

            var user = db.SingleOrDefault <User>(u => u.Email == email);

            cookies.Set(userCookie);

            var rolesCookie = new HttpCookie("roles")
            {
                Value = string.Join(",", user.UserRoles.Select(r => r.Code)), Expires = DateTime.Now.AddDays(30)
            };

            cookies.Set(rolesCookie);

            return(model.access_token);
        }
Example #3
0
        public static TokenModel GetToken(HttpRequestBase request)
        {
            var code = request.QueryString["code"];

            var stream = HttpTools.PostStream("https://oauth.yandex.ru/token",
                                              string.Format("grant_type=authorization_code&code={0}&client_id={1}&client_secret={2}", code, ClientId, Password));

            var model = SerializeTools.Deserialize <TokenModel>(stream);

            return(model);
        }
Example #4
0
        public static TokenModel GetToken(HttpRequestBase request)
        {
            var code = request.QueryString["code"];

            var stream = HttpTools.PostStream("https://connect.mail.ru/oauth/token",
                                              string.Format(
                                                  "client_id={0}&" +
                                                  "client_secret={1}&" +
                                                  "grant_type=authorization_code&" +
                                                  "code={2}&" +
                                                  "redirect_uri={3}",
                                                  SiteId, SecretKey, code, RedirectUri));

            var model = SerializeTools.Deserialize <TokenModel>(stream);

            return(model);
        }
Example #5
0
        public static UserModel GetUser(HttpRequestBase request)
        {
            var model = new UserModel {
                IsAutharization = false
            };

            try
            {
                var userCookie = request.Cookies["yandex_token"];
                if (userCookie != null)
                {
                    var stream = HttpTools.PostStream(InfoUrl, string.Format("oauth_token={0}", userCookie.Value));
                    model = SerializeTools.Deserialize <UserModel>(stream);
                    model.IsAutharization = true;
                }
            }
            catch (Exception)
            {
                //MonitorLog.WriteLog(ex.InnerException + ex.Message, MonitorLog.typelog.Error, true);
                model.IsAutharization = false;
            }

            return(model);
        }