public static SocialLoginModel MapSocialLogin(SocialLogin socialLogin) { var model = new SocialLoginModel(); model.Assign(socialLogin); return(model); }
public static SocialLogin MapSocialLogin(SocialLoginModel model) { var socialLogin = new SocialLogin(); socialLogin.Assign(model); return(socialLogin); }
private void CreateAndAssignNewSocialLoginForApplicationUser(Claim identifier, AuthenticationTypeProvider authenticationTypeProvider, User newUser) { var socialLogin = new SocialLogin(identifier.Value, authenticationTypeProvider, newUser.Id); this.socialLoginRepository.SaveToDatabase(socialLogin); }
public string SocialLogin(SocialLogin model) { SetJsonHeader(); var content = GetPostParameters(); //证书的路径 var certification = GetCertificationFilePath(); //证书的密码 var certificationPwd = GetCertificationPwd(); string result = HttpAsynchronousTool.CustomHttpWebRequestPost(GetCurrentUrl(this), content, certification, certificationPwd); return(result); }
public async Task AddSocialLogin(string userId, SocialLoginModel model) { var socialLogin = new SocialLogin { Name = model.Name, Key = model.Key, SocialLoginId = model.SocialLoginId, Provider = model.Provider, UserId = model.UserId }; _context.Set <SocialLogin>().Add(socialLogin); await _context.SaveChangesAsync(); model.SocialLoginId = socialLogin.SocialLoginId; }
public async Task <UserAdminDto> ChangeUserStatus(SocialLogin user) { var exUser = _liveContext.Users.FirstOrDefault(x => x.UserEmail == user.Email && x.AuthType == user.AuthType); //Console.WriteLine("-----" + user.Email); // Console.WriteLine("-----" + user.AuthType); if (exUser != null) { exUser.ChangeStatus(); _liveContext.Update(exUser); await _liveContext.SaveChangesAsync(); return(_autoMapper.Map <UserAdminDto>(exUser)); } return(null); }
protected void Page_Load(object sender, EventArgs e) { #region Facebook Login if (HttpContext.Current.Session["cCeSTO_fB_Ken"] != null) { string json = GetFacebookUserJSON(HttpContext.Current.Session["cCeSTO_fB_Ken"].ToString()); JavaScriptSerializer js = new JavaScriptSerializer(); FacebookUser oUser = js.Deserialize <FacebookUser>(json); if (oUser != null) { lblfbName.Text = string.IsNullOrEmpty(oUser.name) ? string.Empty : oUser.name; lblfbFirstName.Text = string.IsNullOrEmpty(oUser.first_name) ? string.Empty : oUser.first_name; lblfbLastName.Text = string.IsNullOrEmpty(oUser.last_name) ? string.Empty : oUser.last_name; lblfbemail.Text = string.IsNullOrEmpty(oUser.email) ? string.Empty : oUser.email; lblfbGender.Text = string.IsNullOrEmpty(oUser.gender) ? string.Empty : oUser.gender; lblfbLink.Text = string.IsNullOrEmpty(oUser.link) ? string.Empty : oUser.link; lblfbPicture.Text = string.IsNullOrEmpty(oUser.picture) ? string.Empty : oUser.picture; lblfbid.Text = oUser.id.ToString(); ObjFb.FBName = lblfbName.Text; ObjFb.FirstName = lblfbFirstName.Text; ObjFb.LastName = lblfbLastName.Text; ObjFb.Gender = lblfbGender.Text; ObjFb.Link = lblfbLink.Text; ObjFb.Picture = lblfbPicture.Text; ObjFb.FBID = oUser.id.ToString(); ObjFb.EMail = lblfbemail.Text; ObjFb.ST = "F"; MEMBERS.SQLReturnValue MVal = SocialLogin.AUTHFacebookLogin(ObjFb); if (MVal.ValueFromSQL > 0) { Session["USERNAME"] = lblfbFirstName.Text; Session["cCeSTO_fB_Ken"] = null; MyLogic.GetUserID = MVal.ValueFromSQL.ToString(); Response.Redirect("Default.aspx"); } else { Session["cCeSTO_fB_Ken"] = null; ScriptManager.RegisterStartupScript(this, this.GetType(), "noti", "setMessage('facebook login Failed Please Try Again emailid not valid.',1);", true); } } } else { Session["cCeSTO_fB_Ken"] = null; } #endregion #region Google Login if (HttpContext.Current.Session["cCeSTO_goG_Ken"] != null) { string jsonG = GetGoogleUserJSON(HttpContext.Current.Session["cCeSTO_goG_Ken"].ToString()); JavaScriptSerializer jsG = new JavaScriptSerializer(); GoogleUser profile = new JavaScriptSerializer().Deserialize <GoogleUser>(jsonG); if (profile != null) { lblfbName.Text = string.IsNullOrEmpty(profile.name) ? string.Empty : profile.name; lblfbFirstName.Text = string.IsNullOrEmpty(profile.given_name) ? string.Empty : profile.given_name; lblfbLastName.Text = string.IsNullOrEmpty(profile.family_name) ? string.Empty : profile.family_name; lblfbemail.Text = string.IsNullOrEmpty(profile.email) ? string.Empty : profile.email; lblfbGender.Text = string.IsNullOrEmpty(profile.gender) ? string.Empty : profile.gender; lblfbLink.Text = string.IsNullOrEmpty(profile.link) ? string.Empty : profile.link; lblfbPicture.Text = string.IsNullOrEmpty(profile.picture) ? string.Empty : profile.picture; lblfbid.Text = profile.id.ToString(); ObjFb.FBName = lblfbName.Text; ObjFb.FirstName = lblfbFirstName.Text; ObjFb.LastName = lblfbLastName.Text; ObjFb.Gender = lblfbGender.Text; ObjFb.Link = lblfbLink.Text; ObjFb.Picture = lblfbPicture.Text; ObjFb.FBID = profile.id.ToString(); ObjFb.EMail = lblfbemail.Text; ObjFb.ST = "G"; MEMBERS.SQLReturnValue MVal = SocialLogin.AUTHFacebookLogin(ObjFb); if (MVal.ValueFromSQL > 0) { Session["USERNAME"] = lblfbFirstName.Text; Session["cCeSTO_goG_Ken"] = null; MyLogic.GetUserID = MVal.ValueFromSQL.ToString(); Response.Redirect("Default.aspx"); } else { Session["cCeSTO_goG_Ken"] = null; ScriptManager.RegisterStartupScript(this, this.GetType(), "noti", "setMessage('Google + login Failed Please Try Again emailid not valid.',1);", true); } } else { Session["cCeSTO_goG_Ken"] = null; } } #endregion }
public void SaveToDatabase(SocialLogin socialLogin) { this.itanDatabaseContext.SocialLogins.Add(socialLogin); this.itanDatabaseContext.SaveChanges(); }
// POST: api/<controller>/SocialLogin public async Task <IActionResult> SocialLogin([FromBody] SocialLogin model) { VerifyToken(model.IdToken); if (verifyToken) { var user = await _userManager.FindByEmailAsync(googleApiTokenInfo.email); if (user != null) { var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim("UserID", user.UserName.ToString()), new Claim("Roles", "ru") }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature) }; var tokenHandler = new JwtSecurityTokenHandler(); var securityToken = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.WriteToken(securityToken); return(Ok(new { token, user })); /* return Ok(new * { * token, * username = user.UserName, * name = user.Name, * lastname = user.Lastname, * email = user.Email, * role = user.Role, * picture = user.Image, * phone = user.PhoneNumber, * friends = user.Friends, * friendsRequest = user.FriendRequests, * discountPoints = user.DiscountPoints, * reservedTickets = user.ReservedTickets, * ticketHistory = user.TicketHistory, * reservedCars = user.ReservedCars, * reservedCarsHistory = user.ReservedCarsHistory, * passportNumber = user.PassportNumber * });*/ } else { try { IdentityResult result; User registeredUser = null; do { RandomString(5); registeredUser = new User("ru") { UserName = googleApiTokenInfo.given_name + "_" + randomString, Email = googleApiTokenInfo.email, Name = googleApiTokenInfo.given_name, Lastname = googleApiTokenInfo.family_name, EmailConfirmed = googleApiTokenInfo.email_verified == "true" ? true : false, PhoneNumber = "", Image = googleApiTokenInfo.picture }; result = await _userManager.CreateAsync(registeredUser); } while (result.Errors.ToList().Count > 0 && result.Errors.ToList()[0].Code == "InvalidUserName"); user = await _userManager.FindByEmailAsync(googleApiTokenInfo.email); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new Claim[] { new Claim("UserID", user.UserName.ToString()), new Claim("Roles", "ru") }), Expires = DateTime.UtcNow.AddDays(1), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_appSettings.JWT_Secret)), SecurityAlgorithms.HmacSha256Signature) }; var tokenHandler = new JwtSecurityTokenHandler(); var securityToken = tokenHandler.CreateToken(tokenDescriptor); var token = tokenHandler.WriteToken(securityToken); return(Ok(user)); /*return Ok(new { * token, * username = user.UserName, * name = user.Name, * lastname = user.Lastname, * email = user.Email, * role = user.Role, * picture = user.Image, * phone = user.PhoneNumber, * friends = user.Friends, * friendsRequest = user.FriendRequests, * discountPoints = user.DiscountPoints, * reservedTickets = user.ReservedTickets, * ticketHistory = user.TicketHistory, * reservedCars = user.ReservedCars, * reservedCarsHistory = user.ReservedCarsHistory, * passportNumber = user.PassportNumber * });*/ } catch (Exception e) { throw e; } } } return(BadRequest(new { message = "Something went wrong! Try again later" })); }
public virtual Acknowledgement <User> postData(Fbuser fbuser) { List <User> list = new List <User>(); Acknowledgement <User> payload = new Acknowledgement <User>(); try { int count = 0; list = GetDetails(); foreach (User user in list) { if (user.UserEmail.Equals(fbuser.UserEmail, StringComparison.OrdinalIgnoreCase)) { count++; } } if (count == 0) { User fbusers = new User { UserEmail = fbuser.UserEmail, UserName = fbuser.UserName, UserAddress = "From fb", UserPassword = "******", UserPhoneNumber = "**********", UserType = fbuser.UserType, UserStatus = "valid", }; roomDb.FMRUsers.Add(fbusers); roomDb.SaveChanges(); } List <User> lists = new List <User>(); int id = 0; foreach (User user in roomDb.FMRUsers) { if (user.UserEmail.Equals(fbuser.UserEmail) && (user.UserType.Equals(fbuser.UserType))) { lists.Add(user); id = user.UserId; } } int countloginuser = 0; foreach (var item in roomDb.FMRSociallogin) { if (fbuser.ProviderId.Equals(item.ProviderId)) { countloginuser++; } } if (countloginuser == 0) { SocialLogin socialLogin = new SocialLogin { ProviderName = fbuser.Provider, ProviderId = fbuser.ProviderId, UserId = id, }; roomDb.FMRSociallogin.Add(socialLogin); roomDb.SaveChanges(); } if (lists.Count != 0) { payload.code = 1; payload.Set = lists; payload.Message = "Successfully Loggedin"; return(payload); } else { payload.code = 2; payload.Set = null; payload.Message = "Please Login as Valid User"; return(payload); } } catch (Exception e) { throw e; } //return payload; }
public ActionResult FacebookCallback(string code) { var fb = new Facebook.FacebookClient(); dynamic accessToken = ""; try { dynamic result = fb.Post("oauth/access_token", new { client_id = ConfigurationManager.AppSettings["AppId"], client_secret = ConfigurationManager.AppSettings["AppSecret"], redirect_uri = RedirectUri.AbsoluteUri.Replace("http", "https"), code = code }); accessToken = result.access_token; } catch (Exception) { } // Store the access token in the session for farther use Session["AccessToken"] = accessToken; // update the facebook client with the access token so // we can make requests on behalf of the user fb.AccessToken = accessToken; // Get the user's information dynamic me = fb.Get("me?fields=first_name,middle_name,last_name,id,email"); string email = me.email; string firstname = me.first_name; string middlename = me.middle_name; string lastname = me.last_name; SocialLogin socialLogin = new SocialLogin(); socialLogin.EmailAddress = email; socialLogin.FullName = firstname + (string.IsNullOrEmpty(lastname) ? "" : " " + lastname); socialLogin.IsGoogleLogin = false; socialLogin.FacebookProviderUserId = Convert.ToString(me.id); UserDomainLogic userDomainLogic = new UserDomainLogic(); Message message = userDomainLogic.RegisterUserthroughSociallogin(socialLogin); if (message.MessageType == Domain.Enums.MessageType.Success) { return(RedirectToAction("Dashboard", "User")); } else if (message.MessageType == Domain.Enums.MessageType.NewUser) { TempData["isFromSocialMedia"] = true; return(RedirectToAction("NewRegistrationfromSocialPage", "User", new { sm = true })); } else { ErrorBlock(message.MessageText); return(View("Login")); } //// Set the auth cookie //FormsAuthentication.SetAuthCookie(email, false); //return RedirectToAction("Dashboard", "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("Account", "Login"))); } // User has logged in with provider successfully // Check if user is already registered locally //You can call you user data access method to check and create users based on your model var id = authResult.ExtraData["id"]; string email = authResult.ExtraData["email"]; var name = authResult.ExtraData["name"]; var picture = authResult.ExtraData["picture"]; SocialLogin socialLogin = new SocialLogin(); socialLogin.EmailAddress = email; socialLogin.FullName = name; socialLogin.IsGoogleLogin = true; socialLogin.GoogleProviderUserId = id; socialLogin.GoogleUserProfileImageUrl = picture; UserDomainLogic userDomainLogic = new UserDomainLogic(); var message = userDomainLogic.RegisterUserthroughSociallogin(socialLogin); if (message.MessageType == Domain.Enums.MessageType.Success) { return(RedirectAfterLogin(returnUrl)); } else if (message.MessageType == Domain.Enums.MessageType.NewUser) { TempData["isFromSocialMedia"] = true; return(RedirectToAction("NewRegistrationfromSocialPage", "User", new { sm = true })); } else { ErrorBlock(message.MessageText); return(View("Login")); } }