Пример #1
0
        private void btnSignUp_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            SignupForm.ValidationSummary.Errors.Clear();
            if (SignupForm.ValidateItem())
            {
                var user = SignupForm.CurrentItem as User;

                if (user.Password != user.PasswordConfirm)
                {
                    SignupForm.ValidationSummary.Errors.Add(new ValidationSummaryItem("Password and Confirm Password must match."));
                    return;
                }

                _wait.Show("Contacting server to register account information...");

                ServerManager.Instance.SendUserCommand("SIGNUP",
                                                       HandleServerResponse,
                                                       user.UserName,
                                                       user.Password,
                                                       user.Email,
                                                       user.DisplayName,
                                                       user.BirthDate.Ticks,
                                                       user.SecurityQuestion,
                                                       user.SecurityAnswer);
            }
        }
Пример #2
0
        public async Task <SignupResult> RegisterUserAsync(SignupForm model)
        {
            var newUser = new IdentityUser
            {
                LockoutEnabled = true,
                UserName       = model.UserName
            };

            var emailAttr = new EmailAddressAttribute();

            if (emailAttr.IsValid(model.UserName))
            {
                newUser.Email = model.UserName;
            }

            var result = await _userManager.CreateAsync(newUser, model.Password);

            var signupResult = new SignupResult {
                IsSuccess = result.Succeeded
            };

            if (!result.Succeeded)
            {
                signupResult.Errors = result.Errors.Select(x => x.Description).ToList();
            }
            else
            {
                signupResult.Id = newUser.Id;
            }

            return(signupResult);
        }
Пример #3
0
        /// <summary>
        /// Handles when the SignupForm is complete.
        /// </summary>
        /// <param name="context">The dialog context</param>
        /// <param name="result">The completed form</param>
        /// <returns></returns>
        private async Task SignUpComplete(IDialogContext context, IAwaitable <SignupForm> result)
        {
            SignupForm form = null;

            try
            {
                form = await result;
            }
            catch (OperationCanceledException)
            {
            }

            if (form == null)
            {
                await context.PostAsync("You canceled the form.");
            }
            else
            {
                // Here is where we could call our signup service here to complete the sign-up

                var message = $"Thanks! We signed up **{form.EmailAddress}** in zip code **{form.ZipCode}**.";
                await context.PostAsync(message);
            }

            context.Wait(MessageReceived);
        }
Пример #4
0
 public User(SignupForm signupForm)
 {
     this.Username = signupForm.Username;
     this.Password = signupForm.Password;
     this.Name     = signupForm.Name;
     this.Email    = signupForm.Email;
     this.Phone    = signupForm.Phone;
     this.Dob      = signupForm.Dob;
     this.Gender   = signupForm.Gender;
 }
Пример #5
0
        public IActionResult Signup([FromBody] SignupForm Signup)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (db.User.Where(u => u.Username == Signup.Username).FirstOrDefault() != null)
            {
                return(BadRequest($"Username {Signup.Username} already exists."));
            }

            Signup.Password = Crypto.HashPassword(Signup.Password);

            User newUser = new User(Signup);

            db.User.Add(newUser);

            db.SaveChanges();

            return(Ok("Signup successfully"));
        }
Пример #6
0
        public Result Post([FromBody] SignupForm signupForm)
        {
            if (signupForm.password != signupForm.password2)
            {
                return(ResultFactory.buildFailResult("两次密码不一致!"));
            }

            User user = userService.getUserByUsername(signupForm.username);

            if (user != null)
            {
                return(ResultFactory.buildFailResult("该用户名已存在!"));
            }

            if (userService.addUser(signupForm.username, signupForm.password))
            {
                return(ResultFactory.buildSuccessResult("注册成功!"));
            }
            else
            {
                return(ResultFactory.buildFailResult("出现未知错误!"));
            }
        }
        public void TestInvalidEmail_IsNotSaved()
        {
            var saved = new SignupForm().Signup("J", "Whelehon", "wheelie33@gmailcom");

            Assert.IsFalse(saved);
        }
Пример #8
0
        // GET api/<controller>
        //public IEnumerable<string> Get()
        //public string Get()

        /*public ApiResponse Get()
         * {
         *  //return new string[] { "value1", "value2" };
         *  //return mContext.Roles.Select(r => r.name).ToList();
         *  var resp = new ApiResponse();
         *  try
         *  {
         *      int x = 1;
         *      int y = 0;
         *      //resp.data = mContext.Roles.Select(r => r.name).ToList();
         *      resp.data = mContext.Roles.Where(u => u.id == (x / y)).Select(r => r.name).ToList();
         *  }
         *  catch (Exception ex)
         *  {
         *      resp.error = ex.Message;
         *  }
         *  return resp;
         * }*/

        // GET api/<controller>/5

        /*public string Get(int id)
         * {
         *  //return id.ToString();
         *  return mContext.Users.Where(u => u.id == id).Select(u => u.login).SingleOrDefault();
         * }*/

        public ApiResponse Get([FromUri] SignupForm _signupForm)
        {
            switch (_signupForm.Action)
            {
            case HttpRequestParams.signup: {
                try
                {
                    string newUserName = _signupForm.Login;
                    var    oldUser     =
                        mRepository.UserEC.FindByLogin(newUserName);
                    if (oldUser == null)
                    {
                        Role role = mRepository.RoleEC.Find(2);
                        User user = new User()
                        {
                            login = _signupForm.Login
                            ,
                            password = _signupForm.Password
                            ,
                            Role = role
                            ,
                            role_id = role.id
                        };
                        mRepository.UserEC.Save(user);
                        return(new ApiResponse()
                            {
                                data = new List <User>()
                                {
                                    user
                                }, error = ""
                            });
                    }
                    else
                    {
                        return(new ApiResponse()
                            {
                                data = new List <User>()
                                {
                                }, error = $"User {newUserName} already presents"
                            });
                    }
                }
                catch (Exception ex)
                {
                    return(new ApiResponse()
                        {
                            data = null, error = ex.Message
                        });
                }
            }

            case HttpRequestParams.signin:
            {
                try
                {
                    User user =
                        mRepository.UserEC.FindByLogin(_signupForm.Login);

                    if (user != null && _signupForm.Password == user.password)
                    {
                        HttpContext.Current.Session["username"] = _signupForm.Login;
                        return(new ApiResponse()
                            {
                                data = new List <string>()
                                {
                                    user.login
                                }, error = ""
                            });
                    }
                    else
                    {
                        return(new ApiResponse()
                            {
                                data = null, error = "auth_error"
                            });
                    }
                }
                catch (Exception ex)
                {
                    return(new ApiResponse()
                        {
                            data = null, error = ex.Message
                        });
                }
            }

            case HttpRequestParams.signout:
            {
                try
                {
                    HttpContext.Current.Session["username"] = null;
                    return(new ApiResponse()
                        {
                            data = new List <string>()
                            {
                                "logout"
                            }, error = ""
                        });
                }
                catch (Exception ex)
                {
                    return(new ApiResponse()
                        {
                            data = null, error = ex.Message
                        });
                }
            }

            default:
                return(new ApiResponse()
                {
                    data = null, error = "params_error"
                });
            }
        }
Пример #9
0
        public ActionResult SignIn()
        {
            var model = new SignupForm();

            return(View("Signin", model));
        }
Пример #10
0
        public async Task <IActionResult> RegisterUser([FromBody] SignupForm model)
        {
            var result = await _authService.RegisterUserAsync(model);

            return(Ok(result));
        }
        public void TestHyphenatedLastName_LongerThan20Characters_IsNotSaved()
        {
            var saved = new SignupForm().Signup("J", "wwwwwwwwwwwwwwwwwwwwwwwww-wwwwwwwwwwwwwwwwwwwwwwwww", "*****@*****.**");

            Assert.IsFalse(saved);
        }
Пример #12
0
        public void TestGenericData_IsSaved()
        {
            var saved = new SignupForm().Signup("Jason", "Whelehon", "*****@*****.**");

            Assert.IsTrue(saved);
        }
        public void TestValidEmailKnownSpam_IsNotSaved()
        {
            var saved = new SignupForm().Signup("J", "W", "*****@*****.**");

            Assert.IsFalse(saved);
        }
        public void TestValidEmail_IsSaved()
        {
            var saved = new SignupForm().Signup("J", "W", "*****@*****.**");

            Assert.IsTrue(saved);
        }
Пример #15
0
        public async Task <IHttpActionResult> Register(SignupForm signupForm)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.WithoutFormName()));
            }

            /*
             * if (!Captcha.VerifyResponse(signupForm.Captcha))
             * {
             *  ModelState.AddModelError("signupForm.Captcha", "Captcha failed.");
             *  return BadRequest(ModelState.WithoutFormName());
             * }
             */

            var user = new ApplicationUser()
            {
                UserName = signupForm.Username, Email = signupForm.Email
            };
            IdentityResult result = await UserManager.CreateAsync(user, signupForm.Password);

            if (!result.Succeeded)
            {
                if (string.Join(";", result.Errors).Substring(0, 4) == "Name")
                {
                    ModelState.AddModelError("signupForm.Username", "User Name already taken.");
                    return(BadRequest(ModelState.WithoutFormName()));
                }

                if (string.Join(";", result.Errors).Substring(0, 5) == "Email")
                {
                    ModelState.AddModelError("signupForm.Email", "Email already taken.");
                    return(BadRequest(ModelState.WithoutFormName()));
                }

                return(GetErrorResult(result));
            }

            User nnUser = new User();

            try
            {
                //Adding the user details to the database
                nnUser.SetUserDetails(
                    new UserDetails()
                {
                    Id               = user.Id,
                    Status           = "C",                 // Waiting Confirmation
                    Email            = signupForm.Email,
                    FirstName        = signupForm.FirstName,
                    LastName         = signupForm.LastName,
                    IsImmigrant      = signupForm.IsNewcomer,
                    ConsentToContact = signupForm.ConsentToContact
                });

                nnUser.oDetails.Save();

                //Read the layout file
                string cMailBody    = File.ReadAllText(HostingEnvironment.MapPath(@"~/EMailLayouts/UserProfile/_ConfirmEmailLayout.cshtml"));
                string NNWebsiteURL = ConfigurationManager.AppSettings["NNWebsiteURL"];

                //Replace tokens
                cMailBody = cMailBody.Replace("!NN_WSLINK!", NNWebsiteURL);
                cMailBody = cMailBody.Replace("!NN_TOPIMAGE!", NNWebsiteURL + "/Content/images/tpc-logo.png");
                cMailBody = cMailBody.Replace("!CONFIRM_LINK!", NNWebsiteURL + "/confirmaccount/" + Convert.ToBase64String(Encoding.Unicode.GetBytes(user.UserName + "#" + user.SecurityStamp)));
                cMailBody = cMailBody.Replace("!NN_MAILTO!", "*****@*****.**");
                cMailBody = cMailBody.Replace("!NN_CONTACT_LINK!", NNWebsiteURL + "/contact");

                //Sending Confirmation E-Mail
                NNSMTPSender.Instance.SendMail(cMailBody, "E-Mail Confirmation", nnUser.oDetails.Email, "", true);
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e);
                return(BadRequest(ModelState.WithoutFormName()));
            }

            return(Ok(new {
                confirmMail = nnUser.oDetails.Email
            }));
        }
        public void TestHyphenatedLastName_IsSaved()
        {
            var saved = new SignupForm().Signup("J", "Smith-Johnson", "*****@*****.**");

            Assert.IsTrue(saved);
        }
        public void TestLongLastName_IsNotSaved()
        {
            var saved = new SignupForm().Signup("J", "WhelehonWhelehonWhelehonWhelehon", "*****@*****.**");

            Assert.IsFalse(saved);
        }
        public void TestFirstNameContainsNonAlpha_IsNotSaved()
        {
            var saved = new SignupForm().Signup("12345", "Whelehon", "*****@*****.**");

            Assert.IsFalse(saved);
        }
        public void TestEmailMissingAtSign_IsNotSaved()
        {
            var saved = new SignupForm().Signup("J", "W", "wheelie33gmail.com");

            Assert.IsFalse(saved);
        }