public HttpResponseMessage LoginByPassword([FromBody] LoginUser value) { if (ModelState.IsValid) { UserWithoutPassword user = LogicManager.GetUserDetailsByPassword(value.Password, value.UserName); //TODO:TOKEN return(user != null ?Request.CreateResponse(HttpStatusCode.OK, user): new HttpResponseMessage(HttpStatusCode.Forbidden) { Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter()) }); } ; List <string> ErrorList = new List <string>(); //if the code reached this part - the user is not valid foreach (var item in ModelState.Values) { foreach (var err in item.Errors) { ErrorList.Add(err.ErrorMessage); } } return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter()) }); }
public HttpResponseMessage Put([FromBody] UserWithoutPassword value) { ModelState.Remove("Password"); if (ModelState.IsValid) { return((LogicManager.UpdateUser(value)) ? new HttpResponseMessage(HttpStatusCode.OK) : new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not update in DB", new JsonMediaTypeFormatter()) }); } ; List <string> ErrorList = new List <string>(); //if the code reached this part - the user is not valid foreach (var item in ModelState.Values) { foreach (var err in item.Errors) { ErrorList.Add(err.ErrorMessage); } } return(new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <List <string> >(ErrorList, new JsonMediaTypeFormatter()) }); }
//public int Authenticate(string userName, string password) //{ // var user = GetUserDetailsByPassword(password,userName); // if (user != null ) // { // return user.UserId; // } // return 0; //} public static bool sendMessageToManagers(int idUser, string message) { UserWithoutPassword manager = GetUserManager(idUser); UserWithoutPassword user = GetUserDetails(idUser); if (manager == null) { return(false); } SmtpClient client = new SmtpClient(); client.DeliveryMethod = SmtpDeliveryMethod.Network; client.EnableSsl = true; client.Host = "smtp.gmail.com"; client.Port = 587; System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("*****@*****.**", "207322868"); client.UseDefaultCredentials = false; client.Credentials = credentials; MailMessage msg = new MailMessage(); msg.From = new MailAddress(user.Email); msg.To.Add(new MailAddress(manager.Email.ToString())); msg.Subject = "עזרה "; msg.IsBodyHtml = true; msg.Body = string.Format($"<html><head>הודעה שנשלחה</head><body><p>{message}</br></p></body>"); try { client.Send(msg); return(true); } catch (Exception ex) { return(false); } }
//------------------------------------------- public static bool UpdateUser(UserWithoutPassword user) { string query; query = user.ManagerId == 0 || user.ManagerId == null ? $"UPDATE managertasks.user SET userName='******',departmentUserId={user.DepartmentId} ,email='{user.Email}',userComputer='{user.UserComputer}',numHourWork={user.NumHoursWork} WHERE id={user.UserId} " : $"UPDATE managertasks.user SET userName='******',departmentUserId={user.DepartmentId} ,managerId={user.ManagerId} ,email='{user.Email}',userComputer='{user.UserComputer}',numHourWork={user.NumHoursWork} WHERE id={user.UserId} "; return(DBAccess.RunNonQuery(query) == 1); }
public async Task <ActionResult <UserWithoutPassword> > PostUser(CreateNewUser userToCreate) { System.Diagnostics.Debug.WriteLine($"PostUser: Name: {userToCreate.Name}, Surname {userToCreate.Surname}, ManagerId: {userToCreate.ManagingUserId}, TitleId: {userToCreate.JobTitleId}"); var newUser = await _userService.AddNewUserAsync(userToCreate); var newUserWithoutPassword = new UserWithoutPassword(newUser); return(CreatedAtAction(nameof(GetUser), new { id = newUser.Id }, newUserWithoutPassword)); }
//public int Authenticate(string userName, string password) //{ // var user = GetUserDetailsByPassword(password,userName); // if (user != null ) // { // return user.UserId; // } // return 0; //} public static bool sendMessageToManagers(int idUser, string message) { UserWithoutPassword manager = GetUserManager(idUser); UserWithoutPassword user = GetUserDetails(idUser); if (manager == null) { return(false); } return(SendEmail(user.Email, manager.Email, "עזרה", message)); }
public HttpResponseMessage LoginByComputerUser([FromBody] string ComputerUser) { UserWithoutPassword user = LogicManager.GetUserDetailsComputerUser(ComputerUser); //TODO:TOKEN return(user != null ? new HttpResponseMessage(HttpStatusCode.Created) { Content = new ObjectContent <UserWithoutPassword>(user, new JsonMediaTypeFormatter()) } : new HttpResponseMessage(HttpStatusCode.BadRequest) { Content = new ObjectContent <String>("Can not add to DB", new JsonMediaTypeFormatter()) }); }