Ejemplo n.º 1
0
 public bool Registration(string login, string password, string firstName, string lastName, DateTime dateOfBirth, string email)
 {
     using (var entities = new DataContext())
     {
         User           user           = entities.Users.SingleOrDefault(u => u.Login == login);
         EncryptionHash encryptionHash = new EncryptionHash();
         IRoleService   roleService    = new RoleService(_mapper);
         if (user == null)
         {
             User u = new User()
             {
                 Login       = login,
                 DateOfBirth = dateOfBirth,
                 Email       = email,
                 FirstName   = firstName,
                 LastName    = lastName,
                 Password    = encryptionHash.EncodePassword(password),
                 //Role with id = 1 => 'User'
                 Role           = _mapper.Map <Role>(roleService.GetRole(1075)),
                 TimeOfCreating = DateTime.Now
             };
             user = u;
             entities.Users.Add(user);
             entities.SaveChanges();
         }
         return(user != null);
     }
 }
Ejemplo n.º 2
0
 public bool Login(string username, string password)
 {
     using (var ent = new DataContext())
     {
         UserDTO        user           = _mapper.Map <UserDTO>(ent.Users.FirstOrDefault(u => u.Login == username));
         EncryptionHash encryptionHash = new EncryptionHash();
         return(user != null && user.Password.SequenceEqual(encryptionHash.EncodePassword(password)));
     }
 }