public bool add(Employee employee) { var tmp = new ComMails(); var rnd = new Random(); var pwd = _passwordTools.passwordGen(10); employee.Username = employee.FirstName[0] + employee.LastName + rnd.Next(employee.LastName.Length * 1000).ToString(); employee.Password = _passwordTools.passwordHash(pwd); tmp.Email = new List <string>(); tmp.Email.Add(employee.Email); tmp.Message = "Please find below, your credentials to NRP Portal:<br/>Sign in as Employee<br/>"; tmp.Message += "Username " + employee.Username + "<br/>Password: " + pwd; _comMail.SendMailToPar(tmp); try { _context.Employees.Add(employee); _context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(false); } return(true); }
public bool add(ClientContactInfo clientContact) { var tmp = new ComMails(); var rnd = new Random(); var pwd = _passwordTools.passwordGen(10); clientContact.Username = clientContact.FirstName[0] + clientContact.LastName + rnd.Next(clientContact.LastName.Length * 1000).ToString(); clientContact.Password = _passwordTools.passwordHash(pwd); tmp.Email = new List <string>(); tmp.Email.Add(clientContact.Email); tmp.Message = "Please find below, your credentials to NRP Portal:<br/>Sign in as Client<br/>"; tmp.Message += "Username " + clientContact.Username + "<br/>Password: " + pwd; _comMail.SendMailToPar(tmp); try { clientContact.Date = DateTime.Now; _context.ClientContactInfos.Add(clientContact); _context.SaveChanges(); } catch (Exception e) { Console.WriteLine(e.StackTrace); return(false); } return(true); }
public IActionResult Post([FromBody] PasswordChange value) { var tmp = _repo.getById(value.EmployeeId); if (tmp == null) { return(StatusCode(404)); } value.OldPassword = _tools.passwordHash(value.OldPassword); if (tmp.Password.Equals(value.OldPassword) == false) { return(StatusCode(500)); } tmp.Password = _tools.passwordHash(value.NewPassword); _repo.update(tmp.EmployeeId, tmp); return(StatusCode(200)); }
//bool verifyAccess(string accessTo, string accessCode); public Employee employeeLogin(UserCredentials credentials) { if (credentials.Username == "rmaake" && credentials.Password == "maake82552") { var tmp = new Employee(); tmp.FirstName = "Rapula"; tmp.LastName = "Maake"; tmp.ContactNumber = "+27718493239"; tmp.Username = "******"; tmp.Password = "******"; tmp.AccessCode = "admin:read.admin:delete.admin:write.project:read.project:write.project.delete"; return(tmp); } else if (credentials.Username == "akhanye" && credentials.Password == "akhanye123") { var tmp = new Employee(); tmp.Username = "******"; tmp.Password = "******"; tmp.AccessCode = "Employee:6.Employee:5.Employee:12.Employee:13.Employee:15.Employee:16.Employee:10.Employee:11.InvoiceItem:12.InvoiceItem:13.InvoiceItem:15.InvoiceItem:16.Employee:6.Employee:12.Employee:11.Project:6.Project:5.Project:12.Project:13.Project:15.Project:16.Project:10.Project:11"; return(tmp); } credentials.Password = _tools.passwordHash(credentials.Password); return(_context.Employees.Where(opt => opt.Username.Equals(credentials.Username) && opt.Password.Equals(credentials.Password)).SingleOrDefault()); }