public async Task <LoginResult> AuthenticateAsync(FacebookAccount account, RemoteUser user) { var facebookUser = this.GetFacebookUserInfo(account.Token); if (!this.Validate(facebookUser, account.FacebookUserId, account.Email)) { return(new LoginResult { Status = false, Message = Resources.AccessIsDenied }); } var result = await FacebookSignIn.SignInAsync(this.Tenant, account.FacebookUserId, account.Email, account.OfficeId, facebookUser.Name, account.Token, user.Browser, user.IpAddress, account.Culture) .ConfigureAwait(false); if (result.Status) { if (!await Registrations.HasAccountAsync(this.Tenant, account.Email).ConfigureAwait(false)) { string template = "~/Tenants/{tenant}/Areas/Frapid.Account/EmailTemplates/welcome-email-other.html"; var welcomeEmail = new WelcomeEmail(facebookUser, template, this.ProviderName); await welcomeEmail.SendAsync(this.Tenant).ConfigureAwait(false); } } return(result); }
public async Task <LoginResult> AuthenticateAsync(FacebookAccount account, RemoteUser user) { FacebookUserInfo facebookUser = GetFacebookUserInfo(account.Token); if (!Validate(facebookUser, account.FacebookUserId, account.Email)) { return(new LoginResult { Status = false, Message = "Access is denied" }); } LoginResult result = FacebookSignIn.SignIn(account.FacebookUserId, account.Email, account.OfficeId, facebookUser.Name, account.Token, user.Browser, user.IpAddress, account.Culture); if (result.Status) { if (!Registration.HasAccount(account.Email)) { string template = "~/Catalogs/{catalog}/Areas/Frapid.Account/EmailTemplates/welcome-3rd-party.html"; WelcomeEmail welcomeEmail = new WelcomeEmail(facebookUser, template, ProviderName); await welcomeEmail.SendAsync(); } } return(result); }
protected override void beforeEach() { theUrl = "login/test"; theRequest = new FacebookLoginRequest(); theSignIn = new FacebookSignIn(); MockFor <IFubuRequest>().Stub(x => x.Get <FacebookSignIn>()).Return(theSignIn); MockFor <IUrlRegistry>().Stub(x => x.UrlFor(theSignIn)).Return(theUrl); ClassUnderTest.Write(MimeType.Html.Value, theRequest); string html = MimeType.Html.ToString(); theTag = MockFor <IOutputWriter>() .GetArgumentsForCallsMadeOn(x => x.Write(Arg <string> .Is.Same(html), Arg <string> .Is.NotNull)) [0][1].As <string>(); }
public async Task <HttpResponseMessage> SignInWithFacebook(FacebookSignIn model) { if (model == null) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "No Data")); } if (ModelState.IsValid) { var client = new FacebookClient(model.AccessToken); Facebook.JsonObject me = (Facebook.JsonObject)client.Get("/me?fields=name,first_name,last_name,id,email"); ApplicationUser user = db.Users.Where(x => x.FacebookId == model.UserID).FirstOrDefault(); if (user != null) { user.FacebookToken = model.AccessToken; await db.SaveChangesAsync(); // if (user.FacebookToken == model.AccessToken) { await SignInHelper.SignInAsync(user, true, true); var account = new UserDetail(); account.UserName = user.UserName; account.FirstName = me["first_name"].ToString(); // user.FirstName; account.LastName = user.LastName; account.FacebookId = user.FacebookId; account.isAuthenticated = true; account.Route = user.Route; var rolesForUser = users.GetRoles(user.Id); account.isAdmin = rolesForUser.Contains("Admin"); return(Request.CreateResponse(account)); /* * } else { * return Request.CreateErrorResponse(HttpStatusCode.MethodNotAllowed, "Facebook token differs"); * } * */ } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Facebook id not found")); } } return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState)); }