示例#1
0
        public Users Save(Users x)
        {
            if (x.Id == 0)
            {
                if (ExistsByEmail(x.Email))
                    throw new Exception("Ya existe otro usuario con el mismo correo electrónico");
                x.Salt = PiChallengeHelper.CreateSaltKey(10);
                x.Password = PiChallengeHelper.EncryptText(x.Password.Trim(), x.Salt);
                return CreateEntity(x);
            }
            else
            {
                var db = Load(x.Id);

                db.Name = x.Name ?? db.Name;
                db.LastName = x.LastName ?? db.LastName;

                if (x.Email != null && x.Email != string.Empty)
                    if (!db.Email.Equals(x.Email))
                        if (!ExistsByEmail(x.Email, db.Id))
                            db.Email = x.Email;

                return UpdateEntity(db);
            }
        }
示例#2
0
 public Users Save(NewUserModel x)
 {
     if (ExistsByEmail(x.Email))
         throw new Exception("Ya existe otro usuario con el mismo correo electrónico");
     var newUser = new Users()
     {
         Name = x.Name,
         LastName = x.LastName,
         Email = x.Email
     };
     newUser.Salt = PiChallengeHelper.CreateSaltKey(10);
     newUser.Password = PiChallengeHelper.EncryptText(x.Password.Trim(), newUser.Salt);
     return CreateEntity(newUser);
 }
示例#3
0
        public bool ChangePass(ChangePassModel value)
        {
            var passRecovery = LoadByGuid(value.RecoveryId);

            if (passRecovery.ValidTo >= DateTime.Now)
            {
                using (var userSvc = new UserSvc())
                {
                    var user = userSvc.Load(passRecovery.UserId);
                    user.Salt     = PiChallengeHelper.CreateSaltKey(10);
                    user.Password = PiChallengeHelper.EncryptText(value.Password.Trim(), user.Salt);
                    userSvc.Save(user);
                    return(true);
                }
            }
            return(false);
        }
示例#4
0
        public async Task<Users> Login(string email, string pwd)
        {
            if (email == null)
                email = string.Empty;
            email = email.Trim();

            Users Usuario = FindSingle(x => x.Email.Equals(email.ToLower()));

            if (Usuario == null)
                return null;

            var realpwd = PiChallengeHelper.DecryptText(Usuario.Password, Usuario.Salt);

            if (!realpwd.Equals(pwd))
                return null;

            return Usuario;
        }