Exemple #1
0
        public static List <object> PasswordRecovery(string email)
        {
            using (var dc = new DataClassesDataContext())
            {
                try
                {
                    var ret = new List <object>();
                    var emp = dc.Employees.First(x => x.Email == email && x.IsActive);
                    if (emp.IsActive)
                    {
                        var pass       = RandomString(7);
                        var hashedPass = HashPassword.SaltedHashPassword(pass, emp.Email);
                        emp.Password = hashedPass;
                        dc.SubmitChanges();

                        ret.Add(emp.Name);
                        ret.Add(emp.Email);
                        ret.Add(pass);
                    }

                    return(ret);
                }
                catch (Exception)
                {
                    throw new Exception("Nije izmenjen");
                }
            }
        }
Exemple #2
0
 public static void ChangePassword(int empId, string password)
 {
     using (var dc = new DataClassesDataContext())
     {
         try
         {
             var emp = dc.Employees.First(x => x.EmployeeId == empId && x.IsActive);
             if (emp.IsActive)
             {
                 var hashedPass = HashPassword.SaltedHashPassword(password, emp.Email);
                 emp.Password = hashedPass;
                 dc.SubmitChanges();
             }
         }
         catch (Exception)
         {
             throw new Exception("Nije izmenjen");
         }
     }
 }
Exemple #3
0
 public static Data.DTOs.LoginDto CheckUsernameAndPassword(string email, string password)
 {
     using (DataClassesDataContext dc = new DataClassesDataContext())
     {
         var pass = HashPassword.SaltedHashPassword(password, email);
         var find = dc.Employees.Where(a => a.Email == email && a.Password == pass && a.IsActive == true)
                    .Include(a => a.Role.RolePermissions.Select(x => x.PermissionId))
                    .Select(a => new Data.DTOs.LoginDto()
         {
             Name        = a.Name,
             Email       = a.Email,
             Mobile      = a.Mobile,
             EmployeeId  = a.EmployeeId,
             RoleId      = (int)a.RoleId,
             Permissions = a.Role.RolePermissions.Select(x => x.PermissionId).ToList()
         });
         if (find.Any())
         {
             return(find.First());
         }
         return(null);
     }
 }