Пример #1
0
        public IActionResult Register([FromBody] ApplicationUser user)
        {
            if (user == null)
            {
                return(BadRequest(user));
            }
            if (!regex.IsMatch(user.phone))
            {
                return(BadRequest(user));
            }
            if (user.password.Length < 6)
            {
                return(BadRequest(user));
            }
            if (_userRepository.CheckPhone(user.phone))
            {
                return(BadRequest(user));
            }
            Random rd  = new Random();
            int    num = rd.Next(100000, 999999);

            user.code = num.ToString();
            if (_userRepository.Add(user))
            {
                _smsSender.SendSmsAsync(user.phone, user.code);
                return(StatusCode(201, user));
            }
            else
            {
                return(BadRequest(user));
            }
        }