Esempio n. 1
0
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                Account account = new Account
                {
                    firstName  = model.firstName,
                    lastName   = model.lastName,
                    email      = model.email,
                    password   = model.password.Encrypt(model.email),
                    isVerified = false,
                    createDate = DateTime.Now,
                };

                var _account = accountDAL.FetchByEmail(account.email);

                if (_account != null)
                {
                    TempData["errorMessage"] = "Oops ! It appears that email is already in use ! ";
                    return(View(model));
                }

                accountDAL.createAccount(account);

                _email.SendEmailAddressVerificationEmail(account.email, account.email);

                return(View("RegConfirmation"));
            }
            return(View(model));
        }
Esempio n. 2
0
        public ActionResult Create(CreateViewModel 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 = accountDAL.FetchByEmail(model.email);
                if (existingMember == null)
                {
                    TempData["errorMessage"] = "This user does not exist in the system";
                    return(RedirectToAction("Index"));
                }

                else if (existingMember != null)
                {
                    if (existingMember.isVerified == false)
                    {
                        TempData["errorMessage"] = "This user hasn't verified their email";
                        return(RedirectToAction("Create"));
                    }

                    if (existingMember.isVerified == true)
                    {
                        //admin permissions cannot be given to a user who is already admin
                        var existingAdmin = accountPermissionDAL.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("Index"));
                        }

                        else if (existingAdmin == null)
                        {
                            //adds the admin user to the database
                            accountPermission.accountID = existingMember.accountID;
                            accountPermissionDAL.Create(accountPermission);

                            TempData["successMessage"] = "Success. You have created a new admin user !";
                            return(RedirectToAction("Index"));
                        }
                    }
                }
            }
            model.Permissions = permissionDAL.FetchAll();
            return(View(model));
        }