Beispiel #1
0
 public bool EmailInUse(string email)
 {
     Account account = accountDAO.FetchByEmail(email);
     {
         if (account != null)
         {
             return(true);
         }
         return(false);
     }
 }
Beispiel #2
0
        public ActionResult CreateAccountPermission(AccountPermissionCreateViewModel model)
        {
            if (ModelState.IsValid)
            {
                AccountPermission accountPermission = new AccountPermission()
                {
                    permissionID = model.permissionID,
                    email        = model.email,
                    createDate   = DateTime.Now,
                };

                //admin permissions cannot be added to an account that does not exist on the system
                var existingMember = accountDAO.FetchByEmail(model.email);
                if (existingMember == null)
                {
                    TempData["errorMessage"] = "This user does not exist in the system";
                    return(RedirectToAction("AccountPermissionIndex"));
                }

                //admin permissions cannot be given to a user who has a profile
                if (existingMember != null)
                {
                    var profile = profileDAO.fetchByAccountID(existingMember.accountID);
                    if (profile != null)
                    {
                        TempData["errorMessage"] = "This user is a site member. Site members cannot be admin also !.";
                        return(RedirectToAction("AccountPermissionIndex"));
                    }
                    else if (profile == null)
                    {
                        //admin permissions cannot be given to a user who is already admin
                        var existingAdmin = accountPermissionDAO.FetchByEmail(model.email);
                        if (existingAdmin != null)
                        {
                            TempData["errorMessage"] = "This user is already admin. You can change their permission in Admin Users/Change Permission !";
                            return(RedirectToAction("AccountPermissionIndex"));
                        }

                        else if (existingAdmin == null)
                        {
                            //adds the admin user to the database
                            accountPermission.accountID = existingMember.accountID;
                            accountPermissionDAO.CreateAccountPermission(accountPermission);
                            alertService.AddAdminUserCreatedAlert(accountPermission);     //creates alert for admin news feed
                            TempData["successMessage"] = "Success. You have created a new admin user !";
                            return(RedirectToAction("AccountPermissionIndex"));
                        }
                    }
                }
            }
            model.Permissions = accountPermissionDAO.FetchAllPermissions();
            model.adminUser   = true;
            return(View(model));
        }
Beispiel #3
0
        public ActionResult Login(LoginViewModel model, string email, string password)
        {
            model.userSession = false;
            if (ModelState.IsValid)
            {
                email    = model.email;
                password = model.password.Encrypt(email);
                Account account   = accountDAO.FetchByEmail(email);
                var     adminUser = accountPermissionDAO.FetchByEmail(email);

                //if there is only one account returned - good
                if (account != null)
                {
                    //password matches
                    if (account.password == password)
                    {
                        if (account.emailVerified)
                        {
                            userSession.LoggedIn    = true;
                            userSession.Email       = email;
                            userSession.CurrentUser = accountDAO.FetchById(account.accountID);

                            //redirects users to their appropriate pages
                            if (adminUser != null)
                            {
                                return(RedirectToAction("SiteActivity", "Alert"));
                            }

                            else if (adminUser == null)
                            {
                                var profile = profileDAO.fetchByAccountID(userSession.CurrentUser.accountID);
                                if (profile != null)
                                {
                                    return(RedirectToAction("NewsFeed", "Alert"));
                                }
                                else
                                {
                                    return(RedirectToAction("Create", "Profile"));
                                }
                            }
                        }
                        //if user attempts to login without verifying theiremail account
                        else
                        {
                            emails.SendEmailAddressVerificationEmail(account.email, account.email);
                            TempData["errorMessage"] = @"The login information you provided was correct 
                                but your email address has not yet been verified.  
                                We just sent another email verification email to you.  
                                Please follow the instructions in that email.";
                        }
                    }
                    else
                    {
                        TempData["errorMessage"] = @"We were unable to log you in with that information!";
                        return(RedirectToAction("Login", "Account"));
                    }
                }

                TempData["errorMessage"] = @"We were unable to log you in with that information!";
                return(RedirectToAction("Login", "Account"));
            }
            return(View(model));
        }