Exemple #1
0
        public async Task <ActionResult> LandingPage(Model.User user)
        {
            if (user.Password != user.PasswordCheck)
            {
                ModelState.AddModelError("PasswordCheck", "Verifica password non corretta");
            }

            if (ModelState.IsValid)
            {
                // Verify that user not exist yet
                var tmpUser = await _repository.GetUserByEmailAsync(user.Email);

                // Setting User Role
                user.Role = Constants.EnumUserRole.User;

                //  controllo codice attivazione
                var canRegister = await _repository.CanRegister(user.ActivationCode);

                // This must be in transaction
                if (tmpUser == null)
                {
                    if (canRegister)
                    {
                        // There is a promotable enlistment for the transaction which has a PromoterType value that is not recognized by System.Transactions.
                        // using (var ts = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                        var u = await _repository.AddUserAsync(user);

                        using (var ctx = new IdentityRepository(new IdentityContext()))
                        {
                            ctx.AddUser(new IdentityServerRepository.Model.CustomUser
                            {
                                Username = u.Email,
                                Password = u.Password,
                                Role     = u.Role
                            });
                        }
                        //ts.Complete();
                        user = new Model.User();
                    }
                    else
                    {
                        ModelState.AddModelError("ActivactionCode", "Codice di attivazione non corretto.");
                    }
                }
                else
                {
                    ModelState.AddModelError("Email", "Utente già registrato");
                }
            }
            ViewBag.Registrazione = true;
            return(View(user));
        }