public bool LoginDomainUser(DomainUser user) { log.WriteLogEntry("Starting LoginDomainUser..."); bool result = false; string dbServer = WebConfigurationManager.AppSettings.Get("DBServer"); string dbName = WebConfigurationManager.AppSettings.Get("DBName"); log.WriteLogEntry("Starting LDAPHandler..."); LDAPHandler ldapHandle = new LDAPHandler(); if (ldapHandle.ValidateDomain(domainName)) { if (ldapHandle.AuthenticateDomainUser(user)) { log.WriteLogEntry("Starting UserDataHandler..."); UserDataHandler userData = new UserDataHandler(dbServer, dbName); user.UserID = userData.GetUserID(user.DomainUpn); log.WriteLogEntry(string.Format("Current user {0} {1} {2} {3}", user.UserID, user.UserName, user.DomainUpn, user.Authenicated)); result = true; } else { log.WriteLogEntry("FAILED authenticate current user to domain!"); } } else { log.WriteLogEntry("FAILED to validate the domain!"); } log.WriteLogEntry("End LoginDomainUser."); return(result); }
public ActionResult ShowUsers() { UserDataHandler dataSource = new UserDataHandler(); ICollection <UserRegistration> data = dataSource.GetAllUsers(); return(View(data)); }
public ActionResult AddUserPage(UserRegistration user) { if (ModelState.IsValid) { UserDataHandler dataHandler = new UserDataHandler(); dataHandler.AddUser(user); return(RedirectToAction("successPage")); } return(View(user)); }
public ActionResult ChangePassword(UserRegistration user) { if (ModelState.IsValid) { UserDataHandler dataSource = new UserDataHandler(); dataSource.EditPassword(user); return(RedirectToAction("successPage")); } return(RedirectToAction("ErrorLogin")); }
public ActionResult UserRegistrationPage(UserRegistration newUser) { if (ModelState.IsValid) { UserDataHandler dataSource = new UserDataHandler(); dataSource.AddUser(newUser); return(RedirectToAction("successPage")); } return(RedirectToAction("ErrorLogin")); }
public bool NotifyFinance(int notification) { log.WriteLogEntry("Begin NotifyFinance..."); bool result = false; string emailBody = string.Empty; switch (notification) { case 0: emailBody = "<html><body><p>Notifying Finance there is a new travel advance.</p></body></html>"; break; case 1: emailBody = "<html><body><p>Notifying Finance there is a new travel recap.</p></body></html>"; break; } UserDataHandler userData = new UserDataHandler(dbServer, dbName); string financeEmail = userData.GetDepartment(Department.FinanceDept).DeptEmail; ExchangeHandler emailHandle = new ExchangeHandler { EmailSubject = "Notify Finance", RecipientEmailAddress = financeEmail, EmailBody = emailBody }; try { if (emailHandle.ConnectExchangeService()) { log.WriteLogEntry("Connection to Exchange service successful."); if (emailHandle.SendMail()) { result = true; } else { log.WriteLogEntry("Failed send email!"); } } else { log.WriteLogEntry("Failed connect to Exchange service!"); } } catch (Exception ex) { log.WriteLogEntry("Program error " + ex.Message); } log.WriteLogEntry("End NotifyFinance."); return(result); }
public ActionResult DeleteUserPage(FormCollection form) { int num = Convert.ToInt32(form["registerNumber"].ToString()); if (ModelState.IsValid) { UserDataHandler datahandler = new UserDataHandler(); ICollection <UserRegistration> data = datahandler.GetAllUsers(); UserRegistration reg = new UserRegistration(); reg = data.Single(x => x.regnumber == num); data.Remove(reg); return(RedirectToAction("successPage")); } return(RedirectToAction("ErrorLogin")); }
public ActionResult UserLoginPage(UserRegistration user) { UserDataHandler dh = new UserDataHandler(); ICollection <UserRegistration> userData = dh.GetAllUsers(); if (ModelState.IsValid) { if (userData.Any(x => x.password == user.password) && userData.Any(x => x.name == user.name)) { // dataHandler.AddUser(user); return(RedirectToAction("successPage")); } return(RedirectToAction("ErrorLogin")); } return(RedirectToAction("ErrorLogin")); }
public UserDataHandler GetUserByToken(string token) { try { var tokenActive = _context.TokenLogs.FirstOrDefault(x => x.Token == token && x.Active == true && DateTime.Now < x.ValidThru); if (tokenActive == null) { return(null); } else { var user = _context.Users.FirstOrDefault(x => x.Id == tokenActive.UserId); var groups = _context.UserGroups.Where(y => y.UserId == user.Id).ToList(); List <GroupUserList> groupsresult = new List <GroupUserList>(); foreach (var g in groups) { var group = _context.Groups.FirstOrDefault(gr => gr.Id == g.GroupId); GroupUserList groupHandler = new GroupUserList(); groupHandler.Id = g.Id; groupHandler.Descricao = group.Description; groupHandler.Funcao = _context.Functions.FirstOrDefault(y => y.Id == group.FunctionId)?.Description; groupHandler.Inserido = g.CreationDate; groupsresult.Add(groupHandler); } UserDataHandler response = new UserDataHandler { Id = user.Id, Name = user.Name, CPF = user.CPF, Group = groupsresult, Token = token }; return(response); } } catch (System.Exception) { throw; } }
public bool InsertDomainUserSession(DomainUser user) { log.WriteLogEntry("Begin InsertDomainLoginUser..."); bool result = false; string dbServer = WebConfigurationManager.AppSettings.Get("LoginServer"); string dbName = WebConfigurationManager.AppSettings.Get("LoginDB"); UserSession session = new UserSession(user.UserID) { CompanyNumber = user.CompanyNumber, DeptNumber = user.DepartmentNumber, PositionNumber = user.PositionNumber, DomainNumber = user.CompanyNumber, RoleNumber = user.SecurityRoles.FirstOrDefault().RoleNumber, AccessLevel = user.SecurityAccess.FirstOrDefault().AccessNumber, UserName = user.UserName, UserEmail = user.UserEmail, FirstName = user.FirstName, LastName = user.LastName, EmployeeID = user.EmployeeID, DeptName = user.Department.DeptName, DeptHeadName = user.Department.DeptHeadName, DeptHeadEmail = user.Department.DeptHeadEmail, DomainUserName = user.DomainUserName, DomainUpn = user.DomainUpn, SessionKey = user.Token.SessionKey, Authenicated = user.Authenicated, StartTime = DateTime.Now }; log.WriteLogEntry("Starting UserDataHandler..."); UserDataHandler userData = new UserDataHandler(dbServer, dbName); if (userData.InsertUserSession(session)) { result = true; } else { log.WriteLogEntry("Failed inserting domain login user!"); } log.WriteLogEntry("End InsertDomainLoginUser."); return(result); }
public bool LoadUserSession(int userID) { log.WriteLogEntry("Starting LoadUserSession..."); bool result = false; string dbServer = WebConfigurationManager.AppSettings.Get("LoginServer"); string dbName = WebConfigurationManager.AppSettings.Get("LoginDB"); UserSession session = CurrentSession; log.WriteLogEntry("Starting UserDataHandler..."); UserDataHandler userData = new UserDataHandler(session, dbServer, dbName); if (userData.LoadUserSession(userID)) { result = true; } else { log.WriteLogEntry("FAILED to load the current user session!"); } log.WriteLogEntry("End LoadUserSession."); return(result); }
/// <summary> /// setUserData introduced in DOM Level 3 /// Associate an object to a key on this node. The by calling getUserData with the same key. /// </summary> /// <param name="key">The key to associate the object to.</param> /// <param name="data">The object to associate to the given key, or null to remove /// any existing association to that key.</param> /// <param name="handler">The handler to associate to that key, or null.</param> /// <returns>the user data previously associated to the given key on this node, or /// null if there was none.</returns> public object SetUserData(string key, object data, UserDataHandler handler) { for (int i = 0; i < userData.Length; i++) { if (userData[i].key == key) { object result = userData[i].data; userData[i].data = data; userData[i].handler = handler; return(result); } } UserDataItem[] newUserData = new UserDataItem[userData.Length + 1]; for (int i = 0; i < userData.Length; i++) { newUserData[i] = userData[i]; } newUserData[newUserData.Length - 1].key = key; newUserData[newUserData.Length - 1].data = data; newUserData[newUserData.Length - 1].handler = handler; userData = newUserData; return(data); }
private JsonResult saveuser(User user, string command) { Response response = new Response(); UserDataHandler userDataHandler = new UserDataHandler(config); userDataHandler.userId = user.userId; userDataHandler.username = user.username; userDataHandler.password = user.password; userDataHandler.firstName = user.firstName; userDataHandler.lastName = user.lastName; userDataHandler.email = user.email; userDataHandler.userType = user.userType; userDataHandler.gender = user.gender; userDataHandler.dob = user.dob; if (command.Equals("create")) { response.status = userDataHandler.createUser(); } if (command.Equals("update")) { response.status = userDataHandler.updateUser(); } return(Json(response)); }
/// <summary> /// setUserData introduced in DOM Level 3 /// Associate an object to a key on this node. The by calling getUserData with the same key. /// </summary> /// <param name="key">The key to associate the object to.</param> /// <param name="data">The object to associate to the given key, or null to remove /// any existing association to that key.</param> /// <param name="handler">The handler to associate to that key, or null.</param> /// <returns>the user data previously associated to the given key on this node, or /// null if there was none.</returns> public object SetUserData(string key, object data, UserDataHandler handler) { for(int i = 0; i < userData.Length; i++) { if(userData[i].key == key) { object result = userData[i].data; userData[i].data = data; userData[i].handler = handler; return result; } } UserDataItem[] newUserData = new UserDataItem[userData.Length + 1]; for(int i = 0; i < userData.Length; i++) { newUserData[i] = userData[i]; } newUserData[newUserData.Length - 1].key = key; newUserData[newUserData.Length - 1].data = data; newUserData[newUserData.Length - 1].handler = handler; userData = newUserData; return data; }