Example #1
0
        public ActionResult Login(string token)
        {
            ViewData["token"] = token;

            if (string.IsNullOrEmpty(token)) {
                return View();
            } else {
                string rpxApiKey = ConfigurationSettings.AppSettings["RpxApiKey"];
                IRpxLogin rpxLogin = new RpxLogin(rpxApiKey);
                try
                {
                    RpxProfile profile = rpxLogin.GetProfile(token);

                    JavaScriptSerializer js = new JavaScriptSerializer();
                    ViewData["message"] = js.Serialize(profile);
                    FormsAuthentication.SetAuthCookie(profile.DisplayName, false);
                }
                catch (RpxException e )
                {
                    return RedirectToAction("Login");
                    //ViewData["message"] = e.ToString();
                    //return View();
                }
                //return View();
                return RedirectToAction("Welcome", "Account");
            }
        }
Example #2
0
        public virtual ActionResult Login(string token)
        {
            if (string.IsNullOrEmpty(token))
            {
                return View();
            }
            else
            {
                string rpxApiKey = ConfigurationSettings.AppSettings["RpxApiKey"];
                IRpxLogin rpxLogin = new RpxLogin(rpxApiKey);
                try
                {
                    RpxProfile profile = rpxLogin.GetProfile(token);
                    JavaScriptSerializer js = new JavaScriptSerializer();
                    RpxUser rpxUser = this._rpxUserService.GetByIdentifier(profile.Identifier);
                    if (rpxUser == null) { rpxUser = new RpxUser(); }
                    rpxUser.Identifier = profile.Identifier;
                    rpxUser.Url = profile.Url;
                    rpxUser.DisplayName = profile.DisplayName;
                    rpxUser.ProviderName = profile.ProviderName;
                    rpxUser.JsonData = js.Serialize(profile);
                    bool registeredUser = false;
                    if (rpxUser.SiteUserId == null)
                    {
                        var su = this._siteUserService.GetByName(profile.DisplayName);
                        if (su == null)
                        {
                            su = this._siteUserService.Save(new SiteUser { Name = profile.DisplayName });
                            registeredUser = true;
                        }
                        rpxUser.SiteUserId = su.Id;
                    }
                    this._rpxUserService.Save(rpxUser);
                    FormsAuthentication.SetAuthCookie(profile.DisplayName, false);

                    if (registeredUser)
                    {
                        return RedirectToAction(MVC.Account.UserProfile(rpxUser.Id));
                    }
                    else
                    {
                        return RedirectToAction(MVC.Account.Register(rpxUser.Id));
                    }
                    //  RedirectToAction("UserInfo", "Account");

                    //return  RedirectToAction( MVC.Account.UserInfo(rpxUser.Id)); //  RedirectToAction("UserInfo", "Account");
                }
                catch (RpxException )
                {
                    return RedirectToAction("Login");
                }
            }
        }