Example #1
0
 public void RegisterUserTest()
 {
     EFStoreRepository target = new EFStoreRepository(); // TODO: Initialize to an appropriate value
     User user = new User { Email = "*****@*****.**", Password = "******" };
     Customer customer = new Customer { CustomerID ="r1144", CompanyName = "aa", ContactName = "aa", ContactTitle = "aa", Address = "aa", City = "aa", Country = "aa", Fax = "aa", Phone = "aa", PostalCode = "aa", Region = "aa" };
     target.RegisterUserWithCustomer(user, customer);
 }
 public async System.Threading.Tasks.Task<ActionResult> Login(User model, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         if (await authProvider.Authenticate(model.Username, model.Password))
         {
             return Redirect(returnUrl ?? Url.Action("Index", "Admin"));
         }
         else
         {
             ModelState.AddModelError("", "Incorrect username or password");
             return View();
         }
     }
     else
     {
         return View();
     }
 }
        public override MembershipUser CreateUser(string username, string password, string email, string passwordQuestion, string passwordAnswer, bool isApproved, object providerUserKey, out MembershipCreateStatus status)
        {
            ValidatePasswordEventArgs args = new ValidatePasswordEventArgs(username, password, true);
            OnValidatingPassword(args);

            if (args.Cancel)
            {
                status = MembershipCreateStatus.InvalidPassword;
                return null;
            }

            if (RequiresUniqueEmail && GetUserNameByEmail(email) != string.Empty)
            {
                status = MembershipCreateStatus.DuplicateEmail;
                return null;
            }

            MembershipUser user = GetUser(username, true);

            if (user == null)
            {
                User userObj = new User();
                userObj.Email = username;
                userObj.Password = password;

                usersRepository.RegisterUser(userObj);

                status = MembershipCreateStatus.Success;

                return GetUser(username, true);
            }
            else
            {
                status = MembershipCreateStatus.DuplicateUserName;
            }

            return null;
        }
        public ActionResult CompleteRegistration(bool accepted = true)
        {
            //check user registration
            if (Session["UserRegistrationViewModel"] == null)
                return RedirectToAction("UserRegistration", new { app_culture = RouteData.Values["app_culture"] });
            UserRegistrationViewModel userRegistrationModel = (UserRegistrationViewModel)Session["UserRegistrationViewModel"];
            if (!userRegistrationModel.Password.Equals(userRegistrationModel.ConfirmPassword))
                return RedirectToAction("UserRegistration", new { app_culture = RouteData.Values["app_culture"] });
            if (repository.Users.SingleOrDefault(u => u.Email == userRegistrationModel.Email) != null)
                return RedirectToAction("UserRegistration", new { app_culture = RouteData.Values["app_culture"] });

            //check customerMainRegistration
            if (Session["CustomerMainViewModel"] == null)
                return RedirectToAction("CustomerMain", new { app_culture = RouteData.Values["app_culture"] });
            CustomerMainViewModel customerMainModel = (CustomerMainViewModel)Session["CustomerMainViewModel"];
            if (repository.Customers.SingleOrDefault(c => c.CustomerID == customerMainModel.CustomerID) != null)
                return RedirectToAction("CustomerMain", new { app_culture = RouteData.Values["app_culture"] });

            //check customerDetailRegistration
            if (Session["CustomerDetailViewModel"] == null)
                return RedirectToAction("CustomerDetail", new { app_culture = RouteData.Values["app_culture"] });
            CustomerDetailViewModel customerDetailModel = (CustomerDetailViewModel)Session["CustomerDetailViewModel"];

            if (accepted)
            {
                User user = new User { Email = userRegistrationModel.Email, Password = userRegistrationModel.Password };
                Customer customer = new Customer { CustomerID = customerMainModel.CustomerID, CompanyName = customerMainModel.CompanyName, ContactName = customerMainModel.ContactName, ContactTitle = customerMainModel.ContactTitle, Address = customerDetailModel.Address, City = customerDetailModel.City, Country = customerDetailModel.Country, Fax = customerDetailModel.Fax, Phone = customerDetailModel.Phone, PostalCode = customerDetailModel.PostalCode, Region = customerDetailModel.Region };
                user.Customer = customer;
                try
                {
                    repository.RegisterUser(user);
                }
                catch (Exception e)
                {
                    return RedirectToAction("UserRegistration", new { app_culture = RouteData.Values["app_culture"] });
                }
                return RedirectToAction("RegistrationCompleted", new { app_culture = RouteData.Values["app_culture"] });
            }
            else
            {
                return RedirectToAction("UserRegistration", new { app_culture = RouteData.Values["app_culture"] });
            }
        }
Example #5
0
 public void UpdateUser(User user)
 {
     user.Email = user.Email.TrimEnd();
     User user_ = context.Users.Single(u => u.UserID == user.UserID);
     context.Entry(user_).CurrentValues.SetValues(user);
     context.SaveChanges();
     Logger.Info(string.Format("User with Email {0} and password {1} was updated in database", user.Email, user.Password));
 }
Example #6
0
 public void RegisterUser(User user)
 {
     context.Users.Add(user);
     context.SaveChanges();
     Logger.Info(string.Format("User with Email {0} and password {1} was updated in database", user.Email, user.Password));
 }
Example #7
0
 public void DeleteUser(User user)
 {
     User _user = context.Users.SingleOrDefault(u => u.UserID == user.UserID);
     context.Users.Remove(_user);
     context.SaveChanges();
     Logger.Info(string.Format("User with Email {0} and password {1} was deleted from database", user.Email, user.Password));
 }
Example #8
0
 public bool CheckUserConstraint(User user)
 {
     if (context.Users.SingleOrDefault(m => m.Email == user.Email) != null)
         return false;
     else
         return true;
 }