Пример #1
0
        public async Task <ActionResult> UpdateDetails(CustomerInformationModel model)
        {
            HttpCookie WeedHackSesh    = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"];
            var        UserDetails     = MvcApplication.Sessions[WeedHackSesh.Value].User;
            var        CustomerDetails = WeedHackersContext.Customers.ToList().Find(u => u.Id == UserDetails.Id);

            if (ModelState.IsValid)
            {
                var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();
                UserDetails.Email = model.email;
                if (model.password == "")
                {
                    UserDetails.Password = UserDetails.Password;
                }
                UserDetails.Password    = cryptionHelper.HashString(model.password);
                UserDetails.PhoneNumber = model.phonenumber;
                CustomerDetails.Address = model.Address;

                WeedHackersContext.Users.AddOrUpdate(u => u.Id, UserDetails);
                WeedHackersContext.Customers.AddOrUpdate(c => c.Id, CustomerDetails);

                await WeedHackersContext.SaveChangesAsync();

                FlashMessage.Confirmation("Profile Information", "Your information has been updated.");
                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError("Email", "Could not update details!");
            FlashMessage.Danger("Update Unsuccessful", "We could not update your profile. Please ensure you have filled out your new details correctly and try again.");
            return(View("CustomerProfile", model));
            //===============================================================
        }
Пример #2
0
        public async Task <ActionResult> UpdateDetails(EmployeeInformationModel model)
        {
            HttpCookie WeedHackSesh    = System.Web.HttpContext.Current.Request.Cookies["WeedHackersSession"];
            var        UserDetails     = MvcApplication.Sessions[WeedHackSesh.Value].User;
            var        EmployeeDetails = WeedHackersContext.Employees.ToList().Find(u => u.Id == UserDetails.Id);

            if (ModelState.IsValid)
            {
                var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

                if (model.email == null)
                {
                    model.email = UserDetails.Email;
                }
                UserDetails.Email = model.email;

                if (model.password == null)
                {
                    model.password = UserDetails.Password;
                }
                UserDetails.Password = cryptionHelper.HashString(model.password);

                if (model.phonenumber == null)
                {
                    model.phonenumber = UserDetails.PhoneNumber;
                }
                UserDetails.PhoneNumber = model.phonenumber;


                WeedHackersContext.Users.AddOrUpdate(u => u.Id, UserDetails);
                WeedHackersContext.Employees.AddOrUpdate(c => c.Id, EmployeeDetails);

                await WeedHackersContext.SaveChangesAsync();

                return(RedirectToAction("Index"));
            }
            ModelState.AddModelError(model.phonenumber, "Could not add!");
            FlashMessage.Danger("Update Unsuccessful", "We could not update your profile. Please ensure you have filled out your new details correctly and try again.");
            if (EmployeeDetails.EmployeeType.Name == "Employee")
            {
                return(RedirectToAction("EmployeeHome"));
            }
            else if (EmployeeDetails.EmployeeType.Name == "Manager")
            {
                return(RedirectToAction("ManagerHome"));
            }
            else
            {
                return(RedirectToAction("Index"));
            }

            //===============================================================
        }
        public ActionResult ForgotPassword([FromUri] string email, string oldPassword, string newPassword)
        {
            var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

            var user =
                WeedHackersContext.Users.ToList()
                .Find(u => u.Email == email && u.Password == cryptionHelper.HashString(oldPassword));

            if (user != null)
            {
                user.Password = newPassword;
            }
            WeedHackersContext.Users.AddOrUpdate(user);

            return(View());
        }
Пример #4
0
        public async Task <ActionResult> NewEmployee(AdminModel model)
        {
            model.AllDepartments   = WeedHackersContext.Departments.ToList();
            model.AllEmployeeTypes = WeedHackersContext.EmployeeTypes.ToList();
            var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

            var userCheck = WeedHackersContext.Users.ToList().Find(u => u.Email == model.NewUser.Email);

            if (ModelState.IsValid)
            {
                if (userCheck != null)
                {
                    ModelState.AddModelError("Email", "Email already exists! Please use a different email address");
                    FlashMessage.Danger("Invalid Email", "Email already exists! Please use a different email address");
                    return(View("AddEmployee", model));
                }
                var UserEmp = new User
                {
                    Name        = model.NewUser.Name,
                    Surname     = model.NewUser.Surname,
                    Email       = model.NewUser.Email,
                    Password    = cryptionHelper.HashString(model.NewUser.Password),
                    PhoneNumber = model.NewUser.PhoneNumber,
                    SuperAdmin  = false,
                    Deleted     = false
                };
                var newEmployee = new WeedHackers_Data.Entities.Employee
                {
                    Id             = UserEmp.Id,
                    EmployeeTypeId = model.NewEmployee.EmployeeTypeId,
                    DepartmentId   = model.NewEmployee.DepartmentId,
                    Deleted        = false,
                    Timestamp      = DateTime.Now
                };

                WeedHackersContext.Users.Add(UserEmp);
                WeedHackersContext.Employees.Add(newEmployee);
                await WeedHackersContext.SaveChangesAsync();

                return(RedirectToAction("AllEmployees"));
            }
            ModelState.AddModelError("Name", "The Registration process could not be completed! Please ensure you have filled out the form correctly and try again");
            FlashMessage.Danger("Name", "The Registration process could not be completed! Please ensure you have filled out the form correctly and try again");
            return(View("AddEmployee", model));
        }
Пример #5
0
        public async Task <ActionResult> Register(CustomerRegistrationModel model)
        {
            var cryptionHelper = new FrostAura.Dynamics.Core.Helpers.FaCryptographyHelper();

            if (ModelState.IsValid)
            {
                var existingUser = WeedHackersContext.Users.FirstOrDefault(u => u.Email == model.RegistringUser.Email);
                if (existingUser != null)
                {
                    ModelState.AddModelError("Email", "Email already registered");
                    FlashMessage.Danger("{0} is already registered. Please use a different valid email address to register", model.RegistringUser.Email);
                }

                var User = new User
                {
                    Name        = model.RegistringUser.Name,
                    Surname     = model.RegistringUser.Surname,
                    Email       = model.RegistringUser.Email,
                    Password    = cryptionHelper.HashString(model.RegistringUser.Password),
                    PhoneNumber = model.RegistringUser.PhoneNumber,
                    Deleted     = false,
                    Timestamp   = DateTime.Now,
                    SuperAdmin  = false
                };
                WeedHackersContext.Users.Add(User);

                var Customer = new WeedHackers_Data.Entities.Customer
                {
                    Id             = User.Id,
                    Address        = model.RegistringCustomer.Address,
                    CustomerTypeId = model.RegistringCustomer.CustomerTypeId,
                    EmailVerified  = false
                };
                WeedHackersContext.Customers.Add(Customer);

                await WeedHackersContext.SaveChangesAsync();

                var userContext = await WeedHackersContext
                                  .Users
                                  .Include(u => u.Customer.CustomerType)
                                  .Include(u => u.Customer)
                                  .SingleOrDefaultAsync(u => u.Id == model.RegistringUser.Id);

                // Create the session
                var session = new SessionModel
                {
                    Identifier = Guid.NewGuid(),             // Session unique identifier (This gets sent to the client)
                    User       = userContext,                // The mandatory user object a session belongs to
                    ExpiryTime = DateTime.Now.AddMinutes(20) // Session valid for 20 minutes
                };

                // Store the session on the server (As opposed to the database)
                MvcApplication.Sessions[session.Identifier.ToString()] = session;

                // Pass the session to the client via cookies (like before)
                var sessionCookie = new HttpCookie("WeedHackersSession")
                {
                    Value    = session.Identifier.ToString(),
                    Expires  = session.ExpiryTime,
                    HttpOnly = true
                };

                Response.Cookies.Add(sessionCookie);

                //var userContext = (User)ViewBag.UserContext;
                FlashMessage.Confirmation("Registration Successful!", "Welcome to WeedHackers {0}", model.RegistringUser.Name);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ModelState.AddModelError("", "Please fill in all fields and try again");
                FlashMessage.Danger("Error", "Please fill in all fields and try again");
                return(View("Index", model));
            }
        }