Beispiel #1
0
        public bool IsValidRegiterUserBM(RegisterUserBM model)
        {
            if (string.IsNullOrEmpty(model.Email) ||
                string.IsNullOrEmpty(model.Password) ||
                string.IsNullOrEmpty(model.Fullname) ||
                !model.Password.Equals(model.ConfirmPassword))
            {
                return(false);
            }

            if (!model.Email.Contains(".") || !model.Email.Contains("@"))
            {
                return(false);
            }

            if (!Regex.IsMatch(model.Password, "[a-z]{1,}") ||
                !Regex.IsMatch(model.Password, "[A-Z]{1,}") ||
                !Regex.IsMatch(model.Password, "[0-9]{1,}") ||
                model.Password.Length < 6)
            {
                return(false);
            }

            return(!this.Context.Users.All().Any(u => u.Email.Equals(model.Email)));
        }
Beispiel #2
0
        public void AddUser(RegisterUserBM model)
        {
            var user = new User
            {
                Email    = model.Email,
                Password = model.Password,
                Fullname = model.Fullname,
                IsAdmin  = !this.Context.Users.All().Any()
            };

            this.Context.Users.Add(user);
            this.Context.SaveChanges();
        }
Beispiel #3
0
        public IActionResult Register(HttpResponse response, HttpSession session, RegisterUserBM model)
        {
            if (AuthenticationManager.IsAuthenticated(session))
            {
                this.Redirect(response, "/home/all");
                return(null);
            }

            if (!this.service.IsValidRegiterUserBM(model))
            {
                this.Redirect(response, "/home/register");
                return(null);
            }

            this.service.AddUser(model);

            this.Redirect(response, "/home/login");
            return(null);
        }
        public async Task <IActionResult> Register([FromBody] RegisterUserBM model)
        {
            // username validation
            if (await userManager.FindByNameAsync(model.Username) != null)
            {
                throw new BadRequestException($"A user with username { model.Username } already exists.");
            }

            // TO DO: Implement image
            model.ProfilePicture = null;
            var user = mapper.Map <User>(model);

            user.SecurityStamp    = Guid.NewGuid().ToString();
            user.RegistrationDate = DateTime.Now;
            var result = await userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                await userManager.AddToRoleAsync(user, "korisnik");
            }
            await context.SaveChangesAsync();

            return(Ok());
        }