示例#1
0
        public async Task <ActionResult> Register(string email, string password, string passwordRepeat, string firstName, string lastName)
        {
            if (password != passwordRepeat)
            {
                ViewBag.Message = "Password does not match";
                return(View());
            }
            if (!email.Contains("@") || !email.Contains("."))
            {
                ViewBag.Message = "Please enter a valid email address";
                return(View());
            }
            var findExistingEmail = await _userRepository.GetUser(email);

            if (findExistingEmail == null)
            {
                var user = new User
                {
                    Email            = email,
                    FirstName        = firstName,
                    LastName         = lastName,
                    VerificationCode = ObjectId.GenerateNewId().ToString(),
                    Password         = SquibCrypto.HashSha256(password)
                };
                await _userRepository.CreateSync(user);

                FormsAuthentication.SetAuthCookie(email, false);
                return(RedirectToAction("Index", "Home"));
            }
            ViewBag.Message = "Email with the same user already exists.";
            return(View());
        }
示例#2
0
        public override bool ValidateUser(string username, string password)
        {
            var container = new Container();
            container.Options.DefaultScopedLifestyle = new WebRequestLifestyle();
            container.Verify();

            var userRepository = container.GetInstance<UserRepository>();

            var user = Task.Run(() => userRepository.GetUser(username)).Result;
            if (user != null)
            {
                return user.Password == SquibCrypto.HashSha256(password);
            }

            return false;
        }
示例#3
0
        public async Task <JsonResult> RegisterUser(ReqRegisterUser request)
        {
            var findExistingEmail = await _userRepository.GetUser(request.Email);

            if (findExistingEmail == null)
            {
                var organisations = new List <ObjectId>();
                if (!string.IsNullOrEmpty(request.OrganisationName))
                {
                    var newOrganisation = new Organisation
                    {
                        Name = request.OrganisationName
                    };
                    await _organisationRepository.CreateSync(newOrganisation);

                    organisations.Add(newOrganisation.Id);
                }

                var user = new User
                {
                    Email            = request.Email,
                    FirstName        = request.FirstName,
                    LastName         = request.LastName,
                    VerificationCode = ObjectId.GenerateNewId().ToString(),
                    Password         = SquibCrypto.HashSha256(request.Password),
                    Organisations    = organisations
                };
                await _userRepository.CreateSync(user);


                return(Json(new JsonGenericResult
                {
                    IsSuccess = true,
                    Message = user.Id.ToString()
                }));
            }
            return(Json(new JsonGenericResult
            {
                IsSuccess = false,
                Message = "Email with the same user already exists."
            }));
        }