public async Task CreateUser(DataTransformationUser dataTransformationUser)
        {
            User user = new User();

            user.UserName     = dataTransformationUser.UserName;
            user.Password     = SecurityBCryptMethod.CreatePasswordHash(dataTransformationUser.Password);
            user.EmailAddress = dataTransformationUser.EmailAddress;
            user.ExpiresIn    = dataTransformationUser.ExpiresIn;
            user.IPAddress    = dataTransformationUser.IPAddress;
            user.Gender       = dataTransformationUser.Gender;
            user.InExuer      = dataTransformationUser.InExuer;
            user.LimitedTotal = dataTransformationUser.LimitedTotal;
            user.CreatedDate  = DateTime.Now;
            user.CreatedBy    = "";
            user.Deleted      = false;

            user.RoleDetails = new List <UserDetail>();

            foreach (DetailDataTransformationUserRole detailDataTransformationUserRole in dataTransformationUser.RoleDetails)
            {
                UserDetail userDetail = new UserDetail();
                userDetail.Id   = new ObjectId(detailDataTransformationUserRole.id);
                userDetail.Name = detailDataTransformationUserRole.Name;
                user.RoleDetails.Add(userDetail);
            }
            await _context.Users.InsertOneAsync(user);
        }
        public async Task <User> ChangePassword(UserChangePassword user)
        {
            try
            {
                var objUser = new User();
                objUser = await GetUserById(user.id);

                if (objUser != null)
                {
                    //check pass
                    if (SecurityBCryptMethod.VerifyPassword(user.Password, objUser.Password))
                    {
                        // update pass
                        objUser.Password = SecurityBCryptMethod.CreatePasswordHash(user.NewPassword);
                        await Update(objUser);
                    }
                    else
                    {
                        return(null);
                    }
                }

                return(objUser);
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Post([FromBody] User value)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            try
            {
                value.UserName     = value.UserName;
                value.Password     = SecurityBCryptMethod.CreatePasswordHash(value.Password);
                value.ExpiresIn    = value.ExpiresIn;
                value.Gender       = value.Gender;
                value.EmailAddress = value.EmailAddress;
                IPHostEntry heserver  = Dns.GetHostEntry(Dns.GetHostName());
                var         ipAddress = heserver.AddressList.ToList().Where(p => p.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork).FirstOrDefault().ToString();
                // get IP client
                value.IPAddress    = ipAddress;// _accessor.HttpContext.Connection.RemoteIpAddress.ToString();
                value.LimitedTotal = value.LimitedTotal;
                value.InExuer      = value.InExuer;
                value.Deleted      = false;
                value.CreatedDate  = DateTime.Now;
                await _userRepository.Create(value);

                return(new OkObjectResult(value));
            }
            catch (Exception)
            {
                return(BadRequest());
            }
        }