Exemplo n.º 1
0
        public async Task <IActionResult> UserRegisterAsync([FromBody] viUserRegister model)
        {
            var remoteIpAddress = Request.HttpContext.Connection.RemoteIpAddress;

            if (string.IsNullOrEmpty(model.Email) && string.IsNullOrEmpty(model.Password))
            {
                logger.LogInformation($"Login Empty User:{model.Email} Passw:{model.Password} Ip:{remoteIpAddress}");
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }

            var rpUser = db.GetRepository <tbUser>(true) as UserService;
            var user   = await rpUser.CreateUserAsync(model);

            if (user == null)
            {
                logger.LogInformation($"Login BadRequest User:{model.Email} Passw:{model.Password} Ip:{remoteIpAddress}");
                return(BadRequest(new { message = "Username or password is incorrect" }));
            }
            else
            {
                logger.LogInformation($"Login Ok User:{model.Email} Ip:{remoteIpAddress}");
            }

            return(Ok(user));
        }
Exemplo n.º 2
0
        public async Task <viUser> CreateUserAsync(viUserRegister value)
        {
            tbUser res = await db.tbUsers.AsNoTracking()
                         .FirstOrDefaultAsync(x => x.Email == value.Email);

            if (res == null)
            {
                res = new tbUser
                {
                    LastName   = value.LastName,
                    Name       = value.Name,
                    Patronymic = value.Patronymic,
                    Email      = value.Email,
                    Password   = CHash.EncryptMD5(value.Password),
                    Phone      = value.Phone,
                    CreateDate = DateTime.UtcNow,
                    CreateUser = 1,
                    Status     = 1,
                    RoleId     = 1
                };

                await db.tbUsers.AddAsync(res);

                await db.SaveChangesAsync();
            }
            else
            {
                if (res.Password != value.Password)
                {
                    return new viUser()
                           {
                               Status = 0, StatusMessage = "User already exists"
                           }
                }
                ;
            }

            return(GetToken(res));
        }