예제 #1
0
        public async Task <IActionResult> Registration(RegistrationModel model)
        {
            if (ModelState.IsValid)
            {
                ulong phoneULong;
                var   succParse = ulong.TryParse(model.Phone, out phoneULong);
                if (!succParse)
                {
                    return(Problem(statusCode: 400, title: "Pnone incorrect"));
                }
                if (await context.Clients.AnyAsync(c => c.Phone == phoneULong))
                {
                    return(Problem(statusCode: 400, title: "Phone is already in use"));
                }


                var client = new Client()
                {
                    FullName     = model.FullName,
                    Phone        = phoneULong,
                    HashPassword = HashWorker.GetHashString(model.Password)
                };

                await context.Clients.AddAsync(client);

                await context.SaveChangesAsync();

                return(Ok());
            }
            return(BadRequest(ModelState));
        }
예제 #2
0
        public async Task <IActionResult> Auth(AuthModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await context.Clients.FirstOrDefaultAsync(c => c.Phone == model.Phone);

                if (user == null)
                {
                    ModelState.AddModelError("Phone", "This phone not found");
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                if (user.HashPassword != HashWorker.GetHashString(model.Password))
                {
                    ModelState.AddModelError("Auth", "Login or password incorrect");
                    return(BadRequest(new ValidationProblemDetails(ModelState)));
                }
                return(Ok());
            }
            return(BadRequest(ModelState));
        }