public bool CurrentUserHasRole(string role) { if (!IsLoggedIn) return false; var db = new Users(); return db.UserHasRole(CurrentUser, role); }
public AccountController(IFormsAuth formsAuth, IMailer mailer, IFacebookApi facebookApi) { this.users = new Users(); this.pwdResetTokens = new PasswordResetTokens(); this.formsAuth = formsAuth; this.mailer = mailer; this.facebookApi = facebookApi; }
private void AddUserWithFacebookId() { var usersModel = new Users(); usersModel.Register("*****@*****.**", TestUtil.DefaultUserPassword, TestUtil.DefaultUserPassword); usersModel.SetFacebookUserId("*****@*****.**", long.Parse(ConfigurationManager.AppSettings["FacebookTestUserId"])); dynamic user = usersModel.Single(where: "Email = @0", args: "*****@*****.**"); user.IsApproved = true; usersModel.Update(user, user.ID); }
public static void InitDatabase() { DynamicModel dm = new DynamicModel("NietoYostenDb", "Albums", "ID"); dm.Execute("DELETE FROM Pictures"); dm.Execute("DELETE FROM Albums"); dm.Execute("DELETE FROM ApprovalRequests"); dm.Execute("DELETE FROM Users"); var users = new Users(); dynamic testUser = users.Register("*****@*****.**", TestUtil.DefaultUserPassword, TestUtil.DefaultUserPassword); TestUtil.TestUserId = (int)users.Scalar("SELECT ID FROM Users WHERE Email=@0", args:"*****@*****.**"); }
public FacebookApiThrowsWhenGettingEmail() { // Init database (this will delete all users, so there are no users with facebook ids in there). TestUtil.InitDatabase(); this.usersModel = new Users(); this.usersModel.Register("*****@*****.**", TestUtil.DefaultUserPassword, TestUtil.DefaultUserPassword); dynamic user = this.usersModel.Single(where: "Email = @0", args: "*****@*****.**"); user.IsApproved = true; this.usersModel.Update(user, user.ID); this.facebookApi = MockRepository.GenerateStub<IFacebookApi>(); this.facebookApi.Stub(x => x.GetUserEmail(Arg<string>.Is.Anything)).Return(null); this.formsAuth = MockRepository.GenerateMock<IFormsAuth>(); this.accountController = new AccountControllerBuilder().WithJsonRequest().WithFormsAuth(this.formsAuth).WithMailer(this.mailer).WithFacebookApi(this.facebookApi).Build(); this.result = this.accountController.FbLogin( ConfigurationManager.AppSettings["SignedRequest"], ConfigurationManager.AppSettings["AccessToken"], "/Login") as JsonResult; }
private void AddUnApprovedUserWithFacebookId() { var usersModel = new Users(); usersModel.Register("*****@*****.**", TestUtil.DefaultUserPassword, TestUtil.DefaultUserPassword); usersModel.SetFacebookUserId("*****@*****.**", long.Parse(ConfigurationManager.AppSettings["FacebookTestUserId"])); }