Пример #1
0
        protected override void AddAbstract(UserCreateModel entity)
        {
            var    output  = new LogicResult <UserViewModel>();
            int    seconds = DateTime.Now.Second;
            Random rnd     = new Random(seconds);
            string input   = rnd.Next().ToString();
            var    data    = new User
            {
                Email             = entity.Email,
                MobileNumber      = entity.MobileNumber,
                AccessFailedCount = entity.AccessFailedCount,
                Salt          = CHashing.RandomSalt(input),
                LastLoginDate = DateTime.Now,
                UserName      = entity.UserName,
                FirstName     = entity.FirstName,
                LastName      = entity.LastName
            };

            data.Password = CHashing.Hash(entity.Password, data.Salt);
            data.UserClaims.Add(new UserClaim
            {
                ClaimType  = "role",
                ClaimValue = "user"
            });
            this.Uow.GetRepository <User>().Add(data, OtherEntities);
            this.Uow.SaveChanges();
            output.Output = Mapper.Map <User, UserViewModel>(data);
            Result        = output;
        }
Пример #2
0
 public User ValidateUser(string userName, string password)
 {
     try
     {
         var user = this.Uow.GetRepository <User>().Find(x => x.UserName == userName, new string[] { "UserClaims" });
         if (user == null)
         {
             return(null);
         }
         var at = user.Password == CHashing.Hash(password, user.Salt) ? user : null;
         return(at);
     }
     catch (Exception e)
     {
         Console.WriteLine(e);
         throw;
     }
 }