コード例 #1
0
 public ActionResult Index()
 {
     CurrentPage = PageTypes.NewUser;
     var viewModel = new RegisterUserVm { Role = UserRoleType.Alumni };
     PopulateCourses(viewModel.CourseId, viewModel.BranchId);
     return View(viewModel);
 }
コード例 #2
0
 public PartialViewResult RegisterUser(RegisterUserVm model)
 {
     if (ModelState.IsValid)
     {
         try
         {
             var user = _regService.RegisterUser(model);
             _regService.SendEmailValidationToken(user);
             return PartialView("ThankYou", model);
         }
         catch (SimpleException ex)
         {
             ModelState.AddModelError("", ex.Message);
         }
     }
     PopulateCourses(model.CourseId, model.BranchId);
     return PartialView("RegisterUser", model);
 }
コード例 #3
0
 public User RegisterUser(RegisterUserVm userDetails)
 {
     lock (_regSync)
     {
         var user = _db.Users.ToList()
             .FirstOrDefault(u => u.FullName == userDetails.FirstName
                                  && u.UserCourses.Any(c => c.Batch == userDetails.Batch
                                  && userDetails.BranchId == c.BranchId)
                                  && (u.CreateType == UserCreateTypes.Auto || u.CreateType == UserCreateTypes.Admin));
         if (user == null)
         {
             return RegisterNewUser(userDetails);
         }
         else
         {
             return UpgradeAutoToManual(userDetails, user);
         }
     }
 }
コード例 #4
0
 private User ValidateAndUpdateCommonInfo(RegisterUserVm userDetails)
 {
     _userService.ValidateEmailUnique(userDetails.Email);
     var user = userDetails.GetUserEntity();
     var password = userDetails.Password;
     user.AccountStatus = UserRegisterStatus.Approved;
     user.MobileNumber = userDetails.MobileNumber;
     user.HashedPassword = _hashService.CreateHash(password);
     //TODO
     //var role = _db.Roles.Single(r => r.RoleId == (byte)userDetails.Role);
     user.UserRoles.Add(new UserRole
         {
             RoleType = userDetails.Role
         });
     return user;
 }
コード例 #5
0
        private User UpgradeAutoToManual(RegisterUserVm userDetails, User user)
        {
            if (userDetails.Email.ToLower() != user.Email.ToLower())
            {
                _userService.ValidateEmailUnique(userDetails.Email);
            }

            user.Email = userDetails.Email;
            user.MobileNumber = string.IsNullOrEmpty(userDetails.MobileNumber) ? user.MobileNumber : userDetails.MobileNumber;

            user.CreateType = UserCreateTypes.AutoManual;
            user.JoinedOn = DateTime.UtcNow;

            user.AccountStatus = UserRegisterStatus.Approved;
            user.EmailConfirmedOn = null;
            user.MobileNumber = userDetails.MobileNumber;
            user.HashedPassword = _hashService.CreateHash(userDetails.Password);

            _db.Entry(user).State = System.Data.EntityState.Modified;
            _db.SaveChanges();
            AddUserLog(user.UserId, "User converted from auto to manual");
            return user;
        }
コード例 #6
0
 private User RegisterNewUser(RegisterUserVm userDetails)
 {
     var user = ValidateAndUpdateCommonInfo(userDetails);
     if (userDetails.Role == UserRoleType.Alumni || userDetails.Role == UserRoleType.Student)
     {
         UpdateCourseDetails(userDetails.Batch, userDetails.BranchId, user);
     }
     _db.Users.Add(user);
     _db.SaveChanges();
     AddUserLog(user.UserId, "User Register");
     return user;
 }