/// <summary> /// Authenticates user which attempts to sign in /// </summary> /// <param name="signInData">Data to autenticate</param> /// <returns>String containing information about user's permissions</returns> public static async Task <string> AuthenticateCustomer(DtoSignIn signInData) { var c = await new CustomerLogic().GetCustomer(signInData.EMail); if (c == null) { return("Unauthorized"); } var hash = HashPassword(signInData.Password, c); return(hash != c.Password ? "Unauthorized" : c.Name + " " + c.Surname); }
public async Task <HttpResponseMessage> AuthenticateCustomer(DtoSignIn signInData) { var authResult = await AuthenticationLogic.AuthenticateCustomer(signInData); var token = AuthenticationLogic.GetToken(signInData.EMail); var resp = new SignInResponse { AuthorizationResult = authResult, Token = token }; var response = Request.CreateResponse(HttpStatusCode.OK, resp); return(response); }
/// <summary> /// Authenticates user which attempts to sign in /// </summary> /// <param name="signInData">Data to autenticate</param> /// <returns>String containing information about user's permissions</returns> public static async Task <string> Authenticate(DtoSignIn signInData) { var emp = await new EmployeeLogic().GetEmployee(signInData.EMail); if (emp == null) { return("Unauthorized"); } var hash = HashPassword(signInData.Password, emp); if (hash != emp.Password) { return("Unauthorized"); } return(emp.Position.Name == "Admin" ? "Administrator" : "Employee"); }