Ejemplo n.º 1
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email); //try to get user from the user pool
                if (user.Status != null)               // if user exists
                {
                    ModelState.AddModelError("User Exists", "User with this email already exists.");
                    return(View(model));
                }

                /*user attributes should be set before trying to create but depends pool restrictions.
                 * if the attributes are required and hasn't set, then you will get error.
                 *
                 * * dotnet core 3.0 preview
                 * user.Attributes.Add(CognitoAttributesConstants.Name, model.Email);
                 */

                //Set user attirbutes
                user.Attributes.Add(CognitoAttribute.Email.AttributeName, model.Email);
                user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Name);
                user.Attributes.Add(CognitoAttribute.FamilyName.AttributeName, model.Surname);

                //try to create new user
                var createdUser = await _userManager.CreateAsync(user, model.Password).ConfigureAwait(false);

                if (createdUser.Succeeded)                          //if user successfuly created
                {
                    return(RedirectToAction("Confirm", "Account")); //then redirect to Confirm action
                }
            }
            return(View());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Signup(SignupModel signupModel)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(signupModel.Email);

                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User in this email already exists");
                    return(View(signupModel));
                }

                user.Attributes.Add(CognitoAttribute.Name.ToString(), signupModel.Email);

                var CreatedUser = await _UserManager.CreateAsync(user, signupModel.Password).ConfigureAwait(false);

                if (CreatedUser.Succeeded)
                {
                    return(RedirectToAction("Confirm", "Accounts"));
                }
            }


            return(View(signupModel));
        }
Ejemplo n.º 3
0
        public ActionResult Index(SignupModel signup)
        {
            if (!ModelState.IsValid)
            {
                return(View(signup));
            }

            var signupService = new SignupService();

            var ipAddress = Request.ServerVariables["REMOTE_ADDR"];

            signupService.Save(signup, ipAddress);

            //var message = new MailMessage();
            //message.To.Add("*****@*****.**");
            //message.Subject = "New Data Explorer Community Sign-up";
            //message.From = new MailAddress("*****@*****.**");
            //message.Body = new StringBuilder()
            //    .AppendLine("First Name:   " + signup.FirstName)
            //    .AppendLine("Last Name:    " + signup.LastName)
            //    .AppendLine("Email:        " + signup.Email)
            //    .AppendLine("Organization: " + signup.Organization)
            //    .AppendLine("Industry:     " + signup.Industry)
            //    .ToString();

            //var client = new SmtpClient("relay-hosting.secureserver.net");
            //client.Send(message);

            return(RedirectToAction("thankyou"));
        }
Ejemplo n.º 4
0
        public SignUpResponse SignupUser(SignupModel model)
        {
            bool userExists = _context.Appuser.Select(x => x.Email == model.Email).FirstOrDefault();

            if (userExists)
            {
                return(new SignUpResponse {
                    Success = false, Message = "Email Already Exists"
                });
            }

            // Map it
            var user = SignupModelToUsers.Map(model);

            user.Salt     = Salt();
            user.Password = HashPassword(user.Password, user.Salt);

            // Save to the database
            _context.Appuser.Add(user);
            _context.SaveChanges();

            return(new SignUpResponse
            {
                Success = true,
                Message = "Sign Up Successful"
            });
        }
Ejemplo n.º 5
0
        public async Task CannotSignupWhenAccountCreationDisabledWithInvalidTokenAsync(bool enableAdAuth, string email, string password)
        {
            await ResetAsync();

            try {
                _authController.Request = CreateRequestMessage(SIGNUP_ENDPOINT, null, false, false);
                Settings.Current.EnableAccountCreation     = false;
                Settings.Current.EnableActiveDirectoryAuth = enableAdAuth;

                if (enableAdAuth && email == TestDomainLoginProvider.ValidUsername)
                {
                    TestDomainLoginProvider provider = new TestDomainLoginProvider();
                    email = provider.GetEmailAddressFromUsername(email);
                }

                var signupModel = new SignupModel {
                    Email       = email,
                    InviteToken = StringExtensions.GetNewToken(),
                    Name        = "Test",
                    Password    = password
                };
                var actionResult = await _authController.SignupAsync(signupModel);

                Assert.IsAssignableFrom <IHttpActionResult>(actionResult);
                var cancellation = new CancellationToken();
                var result       = await actionResult.ExecuteAsync(cancellation);

                Assert.False(result.IsSuccessStatusCode, "Status Code is success.");
                Assert.Equal(System.Net.HttpStatusCode.BadRequest, result.StatusCode);
                var error = GetErrorMessage(result);
                Assert.Equal("Account Creation is currently disabled.", error);
            } finally {
                await ResetAsync();
            }
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email);
                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User already exists");
                    return(View(model));
                }

                user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);
                var createdUser = await _userManager.CreateAsync(user, model.Password).ConfigureAwait(false);

                if (createdUser.Succeeded)
                {
                    return(RedirectToAction("Confirm"));
                }
                else
                {
                    foreach (var error in createdUser.Errors)
                    {
                        ModelState.AddModelError(error.Code, error.Description);
                    }
                }
            }
            return(View());
        }
Ejemplo n.º 7
0
        public async Task CanSignupWhenAccountCreationEnabledWithNoTokenAsync()
        {
            await ResetAsync();

            try {
                _authController.Request = CreateRequestMessage(SIGNUP_ENDPOINT, null, false, false);
                Settings.Current.EnableAccountCreation = true;

                var signupModel = new SignupModel {
                    Email       = "*****@*****.**",
                    InviteToken = "",
                    Name        = "Test",
                    Password    = "******"
                };
                var actionResult = await _authController.SignupAsync(signupModel);

                var cancellation = new CancellationToken();
                var result       = await actionResult.ExecuteAsync(cancellation);

                var error = GetResult <HttpError>(result);
                if (error != null)
                {
                    _output.WriteLine("Error: {0}", error.Message);
                }
                Assert.True(result.IsSuccessStatusCode, "Status Code is failure.");
                Assert.Equal(System.Net.HttpStatusCode.OK, result.StatusCode);
                var tokenResult = GetResult <TokenResult>(result);
                Assert.NotNull(tokenResult);
                Assert.False(string.IsNullOrEmpty(tokenResult.Token));
            } finally {
                await ResetAsync();
            }
        }
Ejemplo n.º 8
0
        public async Task CanSignupWhenAccountCreationEnabledWithNoTokenAndInvalidAdAccountAsync()
        {
            await ResetAsync();

            try {
                _authController.Request = CreateRequestMessage(SIGNUP_ENDPOINT, null, false, false);
                Settings.Current.EnableAccountCreation     = true;
                Settings.Current.EnableActiveDirectoryAuth = true;

                var signupModel = new SignupModel {
                    Email       = "*****@*****.**",
                    InviteToken = "",
                    Name        = "Test",
                    Password    = "******"
                };
                var actionResult = await _authController.SignupAsync(signupModel);

                var cancellation = new CancellationToken();
                var result       = await actionResult.ExecuteAsync(cancellation);

                Assert.False(result.IsSuccessStatusCode, "Status Code is success.");
                Assert.Equal(System.Net.HttpStatusCode.BadRequest, result.StatusCode);
            } finally {
                await ResetAsync();
            }
        }
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _cognitoUserPool.GetUser(model.Email);
                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User with this email already exists");
                    return(View(model));
                }

                user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);
                var createdUser = await _userManager.CreateAsync(user, model.Password);

                if (createdUser.Succeeded)
                {
                    return(RedirectToAction(nameof(Confirm), new { model.Email }));
                }
                else
                {
                    createdUser.Errors.ToList().ForEach(e => ModelState.AddModelError(e.Code, e.Description));
                }
            }
            return(View(model));
        }
Ejemplo n.º 10
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    CognitoUser user = _pool.GetUser(model.Email);
                    if (user.Status != null)
                    {
                        ModelState.AddModelError("UserExists", "User with this email already exists");
                        return(View(model));
                    }

                    //user.Attributes.Add(CognitoAttributesConstants.Name, model.Email);
                    user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);
                    user.Attributes.Add(CognitoAttribute.Email.AttributeName, model.Email);
                    IdentityResult createdUser = await _userManager.CreateAsync(user, model.Password).ConfigureAwait(false);

                    if (createdUser.Succeeded)
                    {
                        return(RedirectToAction("Confirm"));
                    }
                    else
                    {
                        ModelState.AddModelError("createdUserError", string.Join <string>(" - ", createdUser.Errors.Select(error => error.Description).ToList()));
                    }
                }
            }
            catch (Exception ex)
            {
                ModelState.AddModelError("Somne kind of error", ex.Message);
            }
            return(View(model));
        }
Ejemplo n.º 11
0
        public async Task <IActionResult> SignupPost(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email);

                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User with this email already exists");
                    return(View(model));
                }
                user.Attributes.Add(CognitoAttribute.Email.AttributeName, model.Email);
                user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);

                Dictionary <string, string> validationData = new Dictionary <string, string>(StringComparer.Ordinal)
                {
                    { CognitoAttribute.Email.AttributeName, model.Email },
                    { CognitoAttribute.Name.AttributeName, model.Email },
                };

                var createdUser = await((CognitoUserManager <CognitoUser>)_userManager).CreateAsync(user, model.Password, validationData);


                if (createdUser.Succeeded)
                {
                    return(RedirectToAction("Confirm"));
                }
            }
            return(View(model));
        }
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = context.Users.Where(x => x.Email == model.Email).FirstOrDefault();

                if (user == null)
                {
                    user = new User {
                        Name      = model.Name,
                        Email     = model.Email,
                        HashedPwd = model.Pwd.Hash()
                    };

                    var result = context.Users.Add(user);
                    try {
                        var affected = await context.SaveChangesAsync();

                        if (affected > 0)
                        {
                            return(RedirectToAction("SignupSuccess"));
                        }
                    } catch (Exception ex) {
                        ModelState.AddModelError("", ex.Message);
                        //ModelState.AddModelError("", "לא הצלחנו לרשום אותך למערכת...");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "קיים כבר משתמש עם אימייל זה");
                }
            }
            return(View());
        }
Ejemplo n.º 13
0
        private UserEntity Map_Request_Model(SignupModel request, TokenDetailsEntity token)
        {
            UserEntity mDBEntity = new UserEntity();

            mDBEntity.USERID                   = request.Email;
            mDBEntity.FIRSTNAME                = request.FirstName;
            mDBEntity.LASTNAME                 = request.LastName;
            mDBEntity.EMAILID                  = EncryptDecrypt.EncryptStringAES(request.Email);
            mDBEntity.PASSWORD                 = EncryptDecrypt.EncryptStringAES(request.Password);;
            mDBEntity.ISDCODE                  = request.ISDCode;
            mDBEntity.MOBILENUMBER             = request.ContactNo;
            mDBEntity.COMPANYNAME              = request.CompanyName;
            mDBEntity.TOKEN                    = token.Token;
            mDBEntity.TOKENEXPIRY              = token.TokenExpiry;
            mDBEntity.NOTIFICATIONSUBSCRIPTION = request.NotificationSubscription;
            mDBEntity.SHIPMENTPROCESS          = request.ShipmentProcess;
            mDBEntity.SHIPPINGEXPERIENCE       = request.ShippingExperience;
            mDBEntity.USERTYPE                 = 2;
            mDBEntity.ISTEMPPASSWORD           = 0;
            mDBEntity.ACCOUNTSTATUS            = 0;
            mDBEntity.ISTERMSAGREED            = 1;
            mDBEntity.COUNTRYCODE              = request.COUNTRYCODE;
            mDBEntity.COUNTRYNAME              = request.CountryName;
            mDBEntity.COUNTRYID                = request.UACountryId;
            _userRepository.Save(mDBEntity);
            return(mDBEntity);
        }
        public async Task <IActionResult> SignUp(SignupModel user)
        {
            IdentityUser appUser = new IdentityUser
            {
                UserName = user.Name,
                Email    = user.Email
            };

            var result = await userManager.CreateAsync(appUser, user.Password);

            if (result.Succeeded)
            {
                await signInManager.SignInAsync(appUser, isPersistent : false);

                return(Redirect(user?.ReturnUrl ?? "/Event/Index"));
            }
            else
            {
                var error = result.Errors.First();
                if (ModelState.IsValid)
                {
                    ModelState.AddModelError("", error.Description);
                }
                return(View(user));
            }
        }
Ejemplo n.º 15
0
        public static bool SignUp(SignupModel model)
        {
            using (var client = new LandauPortalWebAPI())
            {
                var signupModel = new SignUp(model.Brand, model.Email);
                signupModel.EntryDate = DateTime.Now;
                signupModel.LastName  = string.Empty;
                signupModel.FirstName = string.Empty;
                signupModel.Phone     = string.Empty;

                try
                {
                    //client.SignUps.CreateSignUps(model.Brand, signupModel);
                    client.SignUps.CreateSignUpsInSalesforce(model.Brand, signupModel);
                    return(true);
                }
                catch (Exception e) {
                    if (e is HttpOperationException)
                    {
                        var httpEx = (HttpOperationException)e;
                        return(httpEx.Response.IsSuccessStatusCode);
                    }
                }
                return(false);
            }
        }
Ejemplo n.º 16
0
 public ActionResult SignupAction(SignupModel model)
 {
     if (ModelState.IsValid)
     {
         model.Email          = model.Email.Trim();
         model.PassWord       = model.PassWord.Trim();
         model.RetypePassWord = model.RetypePassWord.Trim();
         model.Name           = model.Name.Trim();
         if (model.PassWord == model.RetypePassWord)
         {
             var     dao    = new UserDao();
             Account newacc = new Account();
             newacc.Email    = model.Email;
             newacc.Name     = model.Name;
             newacc.PassWord = model.PassWord;
             var result = dao.InsertAcc(newacc);
             if (result >= 0)
             {
                 return(RedirectToAction("Login", "User"));
             }
             else
             {
                 ModelState.AddModelError("", "Email đã tồn tại.");
             }
         }
         else
         {
             ModelState.AddModelError("", "Nhập lại mật khẩu không đúng.");
         }
     }
     return(View("Signup"));
 }
Ejemplo n.º 17
0
        public ActionResult Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = Mapper.Map <SignupModel, User>(model);

                    // ** Facade pattern. Unit of Work pattern.
                    Service.InsertUser(user, model.Password, "Member");

                    WebSecurity.Login(model.Email, model.Password);
                    SetCustomAuthenticationCookie(model.Email, rememberMe: false);

                    return(RedirectToLocal());
                }
                catch (MembershipCreateUserException e)
                {
                    Failure = ErrorCodes.Find(e.StatusCode);
                }
            }
            else
            {
                Failure = "Signup was unsuccessful. Please check all data entries";
            }

            return(View(model));
        }
Ejemplo n.º 18
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email);
                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User with this email already exists");
                    return(View(model));
                }

                user.Attributes.Add(CognitoAttribute.Name.ToString(), model.Email);

                var createdUser = await _userManager.CreateAsync(user, model.Password);

                if (createdUser.Succeeded)
                {
                    return(RedirectToAction("Confirm", "Accounts"));
                }
                else
                {
                    foreach (var item in createdUser.Errors)
                    {
                        ModelState.AddModelError(item.Code, item.Description);
                    }

                    return(View(model));
                }
            }
            return(View(model));
        }
Ejemplo n.º 19
0
        public void AddAccount(SignupModel user)
        {
            var  model      = _mapper.Map <User>(user);
            bool userExist  = _context.Users.Any(x => x.Username == model.Username);
            bool emailExist = _context.Users.Any(x => x.Email == model.Email);

            if (userExist == true || emailExist == true)
            {
                throw new Exception(emailExist == true ? "Email is already in use." : "Username is already in use.");
            }

            byte[] salt = new byte[16];
            using (var rng = RandomNumberGenerator.Create())
            {
                rng.GetBytes(salt);
            }
            model.Salt = Convert.ToBase64String(salt);

            string hashedPassword = Convert.ToBase64String(KeyDerivation.Pbkdf2(
                                                               password: model.Password,
                                                               salt: salt,
                                                               prf: KeyDerivationPrf.HMACSHA1,
                                                               iterationCount: 10000,
                                                               numBytesRequested: 16));

            model.Password = hashedPassword;
            _context.Add(model);
            _context.SaveChanges();
        }
Ejemplo n.º 20
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                CognitoUser user = _pool.GetUser(model.Email);
                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User with this email already exist");
                    return(View(model));
                }
                user.Attributes.Add(CognitoAttributesConstants.Name, model.Email);
                user.Attributes.Add(CognitoAttributesConstants.BirthDate, model.Birthdate);
                var createdUser = await _userManager.CreateAsync(user, model.Password).ConfigureAwait(false);

                if (createdUser.Succeeded)
                {
                    RedirectToAction("Confirm", "Accounts");
                }
                else
                {
                    foreach (var error in createdUser.Errors)
                    {
                        ModelState.AddModelError(string.Empty, error.Description);
                    }
                }
            }
            return(View());
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> SignUp(SignupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            CognitoUser user = _pool.GetUser(model.Email);

            if (user.Status != null)
            {
                ModelState.AddModelError("UserExist", "User already exist!");
                return(View(model));
            }

            user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);

            IdentityResult createdUser = await _userManager.CreateAsync(user, model.Password);

            if (createdUser.Succeeded)
            {
                return(RedirectToAction("Confirm"));
            }

            return(View());
        }
Ejemplo n.º 22
0
 public ActionResult SignUp(SignupModel model)
 {
     if (ModelState.IsValid)
     {
         var user = new User()
         {
             UserName = model.UserName,
             Password = model.Password,
             Email    = model.Email
         };
         var result = accountService.InsertUser(user);
         if (result.Success)
         {
             Session["Authorized"] = true;
             Session["UserName"]   = model.UserName;
             return(Json(true, JsonRequestBehavior.AllowGet));
         }
         else
         {
             model.ModelError = result.ErrorMessage;
             return(PartialView("_SignUp", model));
         }
     }
     else
     {
         return(PartialView("_SignUp", model));
     }
 }
Ejemplo n.º 23
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var user = _pool.GetUser(model.Email);
                    if (user.Status != null)
                    {
                        ModelState.AddModelError("UserExists", "User with email mentioned already exists");
                        return(View(model));
                    }
                    //user.Attributes.Add(CognitoAttribute.UserName.AttributeName, model.Email);
                    var createdUser = await _userManager.CreateAsync(user, model.Password);

                    if (createdUser.Succeeded)
                    {
                        return(RedirectToAction("Confirm"));
                    }
                }
            }
            catch (Exception ex)
            {
            }

            return(View(model));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                var user = _pool.GetUser(model.Email);

                if (user.Status != null)
                {
                    ModelState.AddModelError("UserExists", "User with this email already exists.");

                    return(View(model));
                }

                user.Attributes.Add(CognitoAttribute.Name.ToString(), model.Email);

                var createdUser = await _userManager.CreateAsync(user, model.Password);

                if (createdUser.Succeeded)
                {
                    return(RedirectToAction("Confirm"));
                    //RedirectToPage("./Confirm");
                }
            }

            return(View());
        }
Ejemplo n.º 25
0
        public async Task <IActionResult> Signup(SignupModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = _userPool.GetUser(model.Email);

            if (user.Status != null)
            {
                ModelState.AddModelError("User Exists", "User with this email already exists");
                return(View(model));
            }

            user.Attributes.Add(CognitoAttribute.Name.AttributeName, model.Email);
            var result = await _userManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(error.Code, error.Description);
                }

                return(View(model));
            }

            return(RedirectToAction("Confirm"));
        }
Ejemplo n.º 26
0
        public ServiceResult <SignonDTO> Signup(SignupModel model)
        {
            ServiceResult <SignonDTO> result = new ServiceResult <SignonDTO>();

            if (!ModelState.IsValid)
            {
                result.Code = ReasonCode.MISSING_REQUIRED_FIELDS;
                foreach (string error in ModelState.Values.SelectMany(v => v.Errors.Select(b => b.ErrorMessage)))
                {
                    result.Message += error + Environment.NewLine;
                }

                return(result);
            }

            if (!PinProcessor.TryParse(model.PIN, out string pin))
            {
                result.Code    = ReasonCode.MISSING_REQUIRED_FIELDS;
                result.Message = Resources.PIN格式不正确;
                return(result);
            }


            result.Data = new MerchantAccountComponent().Signup(model.CountryId, model.Cellphone, model.MerchantAccount, model.MerchantName, model.POSSN, model.InvitationCode, pin);
            return(result);
        }
Ejemplo n.º 27
0
        private async void UserSignUp(object parameter)
        {
            PasswordBox             passwordBox             = parameter as PasswordBox;
            MemberServiceProvider   memberService           = new MemberServiceProvider();
            SignupModel             signup                  = new SignupModel();
            CancellationTokenSource cancellationTokenSource = new CancellationTokenSource();

            signup.Username = LoginModel.UserUsername;
            signup.Password = LoginModel.UserPassword;

            try
            {
                var signupDataModel = await memberService.RegisterUserAsync(signup, cancellationTokenSource.Token);

                if (signupDataModel != null)
                {
                    GenericMessageView view = new GenericMessageView();
                    Mediator.Instance.NotifyViewModel(MediatorMessages.GenericMessageViewModel, MediatorMessages.GenericMessageView, view);
                    Mediator.Instance.NotifyViewModel(MediatorMessages.GenericMessageViewModel, MediatorMessages.GenericMessage, "Successfuly created your account.");
                    view.Owner = App.Current.MainWindow;
                    view.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                ShowGenericMessage(ex.Message);
            }
            //passwordBox?.Clear();
            //loginModel.UserUsername = string.Empty;
        }
Ejemplo n.º 28
0
        public ActionResult Signup(SignupModel model)
        {
            if (ModelState.IsValid)
            {
                if (!_logic.CheckUserReg(model.Username))
                {
                    MailAddress from = new MailAddress("*****@*****.**", "Registration");
                    MailAddress to   = new MailAddress(model.Email);
                    MailMessage msg  = new MailMessage(from, to);
                    msg.Subject    = "Подтверждение регистрации";
                    msg.Body       = string.Format("Для завершения регистрации перейдите по ссылке: " + "<a href=\"{0}\" title=\"Подтвердить регистрацию\">{0}</a>", Url.Action("ConfirmEmail", "User", new { userName = model.Username, email = model.Email }, Request.Url.Scheme));
                    msg.IsBodyHtml = true;
                    SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587);
                    smtp.UseDefaultCredentials = false;
                    smtp.Credentials           = new NetworkCredential("*****@*****.**", "Drocsid_2018");
                    smtp.EnableSsl             = true;
                    smtp.Send(msg);
                    _logic.AddUser(model.Username, CreatePasswordHash(model.Password /*_logic.GenerateSalt(model.Password.Length)*/), model.Email);
                    return(RedirectToAction("Confirm", "User", new { email = model.Email }));
                }
                else
                {
                    ModelState.AddModelError("", "Пользователь с таким логином уже существует");
                }
            }

            return(View(model));
        }
Ejemplo n.º 29
0
        public async Task <bool> AddAsync(SignupModel user, CancellationToken ct = default(CancellationToken))
        {
            _context.User.Add(_mapper.Map <User>(user));
            await _context.SaveChangesAsync(ct);

            return(true);
        }
        public ActionResult SignUp(string email)
        {
            var isValid = new EmailAddressAttribute();

            if (isValid.IsValid(email))
            {
                var model = new SignupModel()
                {
                    Brand     = this.CurrentBrand,
                    Email     = email,
                    EntryDate = DateTimeOffset.UtcNow
                };

                var ok = SignUpManager.SignUp(model);
                if (ok)
                {
                    return(RedirectToAction("ThankYou"));
                }
                return(new EmptyResult());
            }
            else
            {
                return(new EmptyResult());
            }
        }
Ejemplo n.º 31
0
        public ActionResult SignUp(SignupModel model)
        {
            if (_securityUserReader.UserExists(model.Email))
                ModelState.AddModelError("Email", "This Email Address is in use");

            if (ModelState.IsValid)
            {
                var email = model.Email;
                var password = model.Password;

                _gate.Dispatch(new SignUpUserCommand(email, password)
                {
                    HostPath = @Url.Action("Activate", null, null, Request.Url.Scheme)
                });
                var user = _securityUserReader.CheckUserCredentials(new CheckUserCredentialsQuery { Email = email, Password = password });
                _authenticationService.LogIn(email, true, user.UserId, user.Roles, false, false);
                _gate.Dispatch(new RunMailerCommand());
                return RedirectToAction("MoreDetails");
            }
            return View("SignUp", model);
        }
Ejemplo n.º 32
0
        public LogonModule (SuperSimpleAuth ssa)
        {
            this.ssa = ssa;

            Get["/settings"] = parameters => {
                SettingsModel model = new SettingsModel();

                if(this.Context.CurrentUser == null)
                {
                    return this.LogoutAndRedirect("/");
                }

                model.Planeswalker = (Planeswalker)this.Context.CurrentUser;
               
                return View["Logon/Settings",model];
            };

            Post["/settings"] = parameters => {
                SettingsModel model = this.Bind<SettingsModel>();

                if(this.Context.CurrentUser == null)
                {
                    return this.LogoutAndRedirect("/");
                }

                model.Planeswalker = (Planeswalker)this.Context.CurrentUser;
               

                if(Request.Form.Save != null)
                {
                    model.Planeswalker.Profile.Email = model.Email;
                    model.Planeswalker.Profile.Name = model.Name;

                    try
                    {
                        model.Planeswalker = repository.UpdatePlaneswalker(model.Planeswalker);
                    }
                    catch(Exception e)
                    {
                        model.Errors.Add("Could not update account");
                        model.Errors.Add(e.Message);
                    }
                }

                if(Request.Form.Delete != null)
                {
                    try
                    {
                        if(model.Yes)
                        {
                            ssa.Disable(model.Planeswalker.AuthToken);
                            repository.RemovePlaneswalker(model.Planeswalker.Id);
                            return this.LogoutAndRedirect("/");
                        }
                        else
                        {
                            model.Errors.Add("You must check, 'Yes, I know'. To delete.");
                        }
                    }
                    catch(Exception e)
                    {
                        model.Errors.Add("Account could not be deleted");
                        model.Errors.Add(e.Message);
                    }
                }

                if(Request.Form.ChangePassword != null)
                {
                    if(model.Password != null && model.ConfirmPassword != null)
                    {
                        if(model.Password == model.ConfirmPassword)
                        {
                            try
                            {
                                ssa.ChangePassword(model.Planeswalker.AuthToken, model.Password);
                                model.Messages.Add("Password successfully changed.");
                            }
                            catch(Exception e)
                            {
                                model.Errors.Add("Password cannot be changed.");
                                model.Errors.Add(e.Message);
                            }  
                        }
                        else
                        {
                            model.Errors.Add("Password and Confirmation Password do not match.");
                        }
                    }
                    else
                    {
                        model.Errors.Add("Password and Confirmation Password must not be blank.");
                    }
                }

                return View["Logon/Settings",model];
            };
           
            Get["/logon"] = parameters => {
                LogonModel model = new LogonModel();
                model.ActiveMenu = "signin";
                model.UrlRedirect = (string)Request.Query.Url;

                if(Request.Query.returnUrl != null)
                {
                    model.UrlRedirect = (string)Request.Query.returnUrl;
                }

                return View["Logon/logon",model];
            };

            Post["/logon"] = parameters => {
                LogonModel model = this.Bind<LogonModel>();
                model.ActiveMenu = "signin";
                var results = this.Validate(model);

                if(!results.IsValid)
                {
                    model.Errors = ErrorUtility.GetValidationErrors(results);
                    return View["Logon/Logon", model];
                }

                model.Errors.Add("Password or/and Username is incorrect.");

                User user = null;

                try
                {
                    user = ssa.Authenticate(model.UserName, model.Secret,
                        this.Context.Request.UserHostAddress);
                }
                catch(Exception e)
                {
                    model.Errors.Add(e.Message);

                    if(user == null)
                    {
                        return View["Logon/logon", model];
                    }
                }

                return this.LoginAndRedirect(user.AuthToken, 
                    fallbackRedirectUrl: model.UrlRedirect);
            };

			Get ["/register"] = parameters => {
                SignupModel model = new SignupModel();
				model.ActiveMenu = "register";
				return View["register", model];
            };

			Post ["/register"] = parameters => {
                SignupModel model = this.Bind<SignupModel>();
                var result = this.Validate(model);
				model.ActiveMenu = "register";

                if (!result.IsValid)
                {
                    model.Errors.AddRange(ErrorUtility.GetValidationErrors(result));
					return View["Register", model];
                }

                try
                {
                    repository.AddPlaneswalker(model.UserName, model.Secret, model.Email);
                }
                catch(Exception e)
                {
                    model.Errors.Add(e.Message);
					return View["Register", model];
                }

                LogonModel logon = new LogonModel();
                logon.Messages.Add("You have successfully created an account. Please Sign In.");

                try
                {
                    Email.send("*****@*****.**", 
                        "New Planeswalker alert", model.UserName);
                }
                catch(Exception e)
                {
                    //swallow this for now
                }

                return View["Logon", logon];

            };

            Get["/logout"] = parameters => {
                Planeswalker nuser = (Planeswalker)Context.CurrentUser;
                ssa.End(nuser.AuthToken);

                return this.LogoutAndRedirect((string)Request.Query.Url);
            };

            Get ["/forgot"] = parameters => {
                ForgotModel model = new ForgotModel();
                model.ActiveMenu = "signin";
                return View["Forgot", model];
            };

            Post ["/forgot"] = parameters => {
                ForgotModel model = this.Bind<ForgotModel>();
                model.ActiveMenu = "signin";

                string subject = "MtgDb.info: Password reset request.";
                string body = "You have requested a password reset. You new password is: {0}";

                try
                {
                    string newPass = ssa.Forgot(model.Email);
                    Email.send(model.Email, subject,string.Format(body,newPass));
                    model.Messages.Add("Your new password has been successfully sent to your email.");
                }
                catch(Exception e)
                {
                    model.Errors.Add(e.Message);
                }
                    
                return View["Forgot", model];
            };
        }