public ActionResult GoogleLogin(string email, string name, string gender, string lastname, string location) { RegisterModel mod = new RegisterModel(); mod.UserName = email; mod.DPName = name; UserModel usermodel = IService.ToFBregisterModel(mod); Locationmodel city = IService.GetUserCountryByIp(); UserSession.UserCountry = city.CountryCode; UserSession.UserName = usermodel.UserName; UserSession.HasSession = true; UserSession.UserId = usermodel.Id; UserSession.LastLoginDate = usermodel.LastLoginTime != null ? usermodel.LastLoginTime.Value : DateTime.Now; if (usermodel.IsAdmin) { UserSession.UserRole = RolesEnum.Admin; UserSession.UserRoleId = RolesEnum.Admin.GetHashCode().ToString(); return(RedirectToAction("Index", "Admin")); } else { UserSession.UserRole = RolesEnum.User; UserSession.UserRoleId = RolesEnum.User.GetHashCode().ToString(); return(RedirectToAction("Index", "User")); } }
public ActionResult FacebookCallback(string code) { var fb = new FacebookClient(); dynamic result = fb.Post("oauth/access_token", new { client_id = "894504637650396", client_secret = "c3896f7433ee29c50272e56374be7831", redirect_uri = RediredtUri.AbsoluteUri, code = code }); var accessToken = result.access_token; Session["AccessToken"] = accessToken; fb.AccessToken = accessToken; dynamic me = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range"); string email = me.email; TempData["email"] = me.email; TempData["first_name"] = me.first_name; TempData["lastname"] = me.last_name; TempData["picture"] = me.picture.data.url; FormsAuthentication.SetAuthCookie(email, false); RegisterModel mod = new RegisterModel(); mod.UserName = me.email; mod.DPName = me.first_name + me.last_name; UserModel usermodel = IService.ToregisterModel(mod); Locationmodel city = IService.GetUserCountryByIp(); UserSession.UserCountry = city.CountryCode; UserSession.UserName = usermodel.UserName; UserSession.HasSession = true; UserSession.UserId = usermodel.Id; UserSession.LastLoginDate = usermodel.LastLoginTime != null ? usermodel.LastLoginTime.Value : DateTime.Now; if (usermodel.IsAdmin) { UserSession.UserRole = RolesEnum.Admin; UserSession.UserRoleId = RolesEnum.Admin.GetHashCode().ToString(); return(RedirectToAction("Index", "Admin")); } else { UserSession.UserRole = RolesEnum.User; UserSession.UserRoleId = RolesEnum.User.GetHashCode().ToString(); return(RedirectToAction("Index", "User")); } }
public ActionResult ExternalLoginCallback(string returnUrl) { string ProviderName = OpenAuth.GetProviderNameFromCurrentRequest(); if (ProviderName == null || ProviderName == "") { NameValueCollection nvs = Request.QueryString; if (nvs.Count > 0) { if (nvs["state"] != null) { NameValueCollection provideritem = HttpUtility.ParseQueryString(nvs["state"]); if (provideritem["__provider__"] != null) { ProviderName = provideritem["__provider__"]; } } } } GoogleOAuth2Client.RewriteRequest(); var redirectUrl = Url.Action("ExternalLoginCallback", new { ReturnUrl = returnUrl }); var retUrl = returnUrl; var authResult = OpenAuth.VerifyAuthentication(redirectUrl); if (!authResult.IsSuccessful) { return(Redirect(Url.Action("Home", "Login"))); } string ProviderUserId = authResult.ProviderUserId; string ProviderUserName = authResult.UserName; string Email = null; if (Email == null && authResult.ExtraData.ContainsKey("email")) { Email = authResult.ExtraData["email"]; } RegisterModel mod = new RegisterModel(); mod.UserName = Email; mod.DPName = ProviderUserName; UserModel usermodel = IService.ToFBregisterModel(mod); Locationmodel city = IService.GetUserCountryByIp(); UserSession.UserCountry = city.CountryCode; UserSession.UserName = usermodel.UserName; UserSession.HasSession = true; UserSession.UserId = usermodel.Id; UserSession.LastLoginDate = usermodel.LastLoginTime != null ? usermodel.LastLoginTime.Value : DateTime.Now; if (usermodel.IsAdmin) { UserSession.UserRole = RolesEnum.Admin; UserSession.UserRoleId = RolesEnum.Admin.GetHashCode().ToString(); return(RedirectToAction("Index", "Admin")); } else { UserSession.UserRole = RolesEnum.User; UserSession.UserRoleId = RolesEnum.User.GetHashCode().ToString(); return(RedirectToAction("Index", "User")); } }