Exemplo n.º 1
0
        public ActionResult ExpressRegister(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                try
                {
                    SecurityService.UserRegister(Context, model);
                    return RedirectToAction("Index", "Scheduler");
                }
                catch (MembershipCreateUserException e)
                {
                    ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
                    Logger.Error(e);
                }
                catch (BusinessException be)
                {
                    ModelState.AddModelError("be", be.Message);
                    Logger.Info(be);
                }
                catch (Exception ex)
                {
                    ModelState.AddModelError("ge", "An unexpected error has occurred");
                    Logger.Error(ex);
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
Exemplo n.º 2
0
        public void UserRegister(ApplicationContext context, RegisterModel model)
        {
            using (var db = new AdministrationDb())
            {
                var user = db.ApplicationUsers.FirstOrDefault(x => x.EmailAddress == model.UserName);
                if (user != null)
                {
                    throw new BusinessException("");
                }
                Logger.Info("Creating Membership");
                MembershipCreateStatus createStatus;
                var membershipUser = Membership.CreateUser(model.UserName,
                    model.Password,
                    model.UserName, "¿?", "!!", true, Guid.NewGuid(), out createStatus);
                Logger.Info("Membership created");
                var created = false;

                if (membershipUser != null && membershipUser.ProviderUserKey != null)
                {
                    var userId = (Guid) membershipUser.ProviderUserKey;
                    var appUser = new ApplicationUser
                    {
                        UserId = userId,
                        FirstName = model.FirstName,
                        LastName = model.LastName,
                        EmailAddress = model.UserName,
                        IsEmailVerified = true,
                        EmailVerificationToken = string.Empty,
                        IsActive = true,
                        CreatedOn = DateTime.Now,
                        CreatedBy = context.UserId,
                        ModifiedOn = DateTime.Now,
                        ModifiedBy = context.UserId,
                        
                    };

                    db.ApplicationUsers.Add(appUser);
                    db.SaveChanges();
                    var customerUser = new CustomerUser
                    {
                        ApplicationUserId = userId,
                        CustomerId = context.TenantId,
                        IsCreator = false,
                        IsAdmin = false,
                        IsRelationActive = true
                    };
                    db.CustomerUsers.Add(customerUser);
                    db.SaveChanges();

                }
            }
        }