public ResLogin LoginWithFacebook(ReqLoginWithFacebook req) { var accessToken = HttpContext.Current.Request["accessToken"]; HttpContext.Current.Session["AccessToken"] = accessToken; var client = new FacebookClient(accessToken); dynamic result = client.Get("me", new { fields = "id,name,email,gender,first_name,last_name,picture" }); req = new ReqLoginWithFacebook() { FacebookId = result.id, Name = result.first_name, Surname = result.last_name, Avatar = result.picture.data.url, Email = result.email, Nick = result.username, Gender = result.gender == "male" ? "M" : "F" }; var res = Call <ResLogin, ReqLoginWithFacebook>(req, MethodBase.GetCurrentMethod().Name); this.SessionId = res.SessionId; HttpContext.Current.Session["Member"] = res.Member; return(res); }
public ResLogin LoginWithFacebook(ReqLoginWithFacebook req) { if (!req.Email.IsEmail()) { throw new APIException("Email address is invalid", ErrorTypes.ValidationError); } if (!string.IsNullOrWhiteSpace(Session.MemberId)) { return new ResLogin() { Member = Session.Member().ToEntityInfo <MemberInfo>(), SessionId = Session.Id } } ; Member member = Provider.Database.Read <Member>("FacebookId={0}", req.FacebookId); if (member != null) { return(doLoginForMember(member)); } member = Provider.Database.Read <Member>("Email={0}", req.Email); if (member != null) { if (string.IsNullOrWhiteSpace(member.Avatar)) { member.Avatar = req.Avatar; } member.FacebookId = req.FacebookId; if (string.IsNullOrWhiteSpace(member.FirstName)) { member.FirstName = req.Name; } if (string.IsNullOrWhiteSpace(member.LastName)) { member.LastName = req.Surname; } if (string.IsNullOrWhiteSpace(member.Gender)) { member.Gender = req.Gender; } member.Save(); return(doLoginForMember(member)); } member = new Member { Email = req.Email, MemberType = MemberTypes.Individual, State = MemberStates.ConfirmedWithFacebook, // facebook'tan gelen üye default onaylıdır (no need for email confirmation) Avatar = req.Avatar, FacebookId = req.FacebookId, FirstName = req.Name, LastName = req.Surname, UserName = req.Nick, Gender = req.Gender, LastLoginDate = Provider.Database.Now, ClientId = this.ApiClient.ClientId, StaffMemberId = Provider.Api.GetNextIdleStaffMemberId(Departments.Marketing) }; member.Save(); member.SendEmailWithPassword(); return(doLoginForMember(member)); }