private void client_LoginCompleted(object sender, LoginCompletedEventArgs e) { ClientInstance.HideSpinner(); Logger.Instance().Log(MessageType.Information, "Login Completed"); if (ErrorHandler.Handle(e.Error)) { passwordTxtBox.Password = string.Empty; userNameTxtBox.Focus(); userNameTxtBox.SelectAll(); return; } Employee employee = new Employee(); if (e.Result != null) { employee = (Employee)e.Result; string aesPassword = CryptographyStuff.AES_DecryptString(employee.Password); employee.Password = aesPassword; User currentUser = new User(employee); this.Content = new Main(currentUser); } else { Logger.Instance().Log(MessageType.Error, "Result is NULL"); } }
private void ClickLogin(object sender, RoutedEventArgs e) { noteLabel.Visibility = System.Windows.Visibility.Collapsed; if (userNameTxtBox.Text == "") { ShowMessage("Please input your name.", MessageType.Error); } else if (passwordTxtBox.Password == "") { ShowMessage("Please input your password.", MessageType.Error); } else { string email = userNameTxtBox.Text.ToLower().Trim() + emailSuffix.Content.ToString(); ClientInstance.ShowSpinner(); if (CarsConfig.Instance().DoSavePW) { LoginInfo loginInfo = new LoginInfo(); loginInfo.UserName = email; loginInfo.Password = passwordTxtBox.Password; CarsConfig.Instance().SaveLoginInfo(loginInfo); } ClientInstance.Get().LoginAsync(email, CryptographyStuff.AES_EncryptString(passwordTxtBox.Password)); } }
public static Employee AddEmployee(string email, string firstName, string middleName, string lastName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string costCenterCode, int employeeNum, string legalName) { Employee employee = null; if (!string.IsNullOrEmpty(email) && !string.IsNullOrEmpty(firstName) && !string.IsNullOrEmpty(lastName)) { employee = Employee.CreateEmployee(email, CryptographyStuff.AES_EncryptString(GlobalParams.DefaultPwd), gender, firstName, dateOfHire, lastName); employee.MiddleName = middleName; employee.Gender = gender; employee.ServiceYears = serviceYear; employee.IsActive = true; employee.EmployeeNum = employeeNum; employee.LegalName = legalName; Role role = Role.GetRoleByName(RoleRank.Employee.ToString()); List <EmployeeRoleRL> employeeRoleList = new List <EmployeeRoleRL>(); employeeRoleList.Add(EmployeeRoleRL.CreateEmployeeRoleRL(Guid.Empty, role.PKRoleID)); employee.SetRoleList(employeeRoleList); if (!string.IsNullOrEmpty(supervisorEmail)) { List <SearchCondition> conditions = new List <SearchCondition>(); conditions.Add(SearchCondition.CreateSearchCondition(GlobalParams.Email, supervisorEmail, SearchComparator.Equal, SearchType.SearchString)); Employee manager = CommonDAL <Employee> .GetSingleObject(conditions); employee.FKReportManagerID = manager.PKEmployeeID; } employee.CostCenter = costCenterCode; employee.Save(); } return(employee); }
/// <summary> /// Register a new employee in system and send an email to hime/her with default password. /// </summary> /// <param name="email">This email should be a valid email address as system will send register email to it.</param> /// <param name="firstName">Not null in database.</param> /// <param name="middleName">Could be null in database.</param> /// <param name="lastName">Not null in database.</param> /// <param name="gender">Not null in database.</param> /// <param name="serviceYear">Count how many years the worker works.</param> /// <param name="dateOfHire">Hired date in our company.</param> /// <param name="supervisorEmail">Could be null in database. The email of his/her manager.</param> /// <returns>Return type is Employee. Returns the employee who is registered just now.</returns> public Employee AddEmployee(string email, string firstName, string middleName, string lastName, string legalName, Sex gender, float serviceYear, DateTime dateOfHire, string supervisorEmail, string costCenterCode, int employeeNum) { Log.Info(GlobalParams.StartAddEmpl); Employee newEmployee = null; try { newEmployee = EmployeeBLL.AddEmployee(email, firstName, middleName, lastName, gender, serviceYear, dateOfHire, supervisorEmail, costCenterCode, employeeNum, legalName); EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); // If add new employee, send a notification email to user. if (newEmployee != null && EmailConfig.EmailTemplates.ContainsKey(EmailType.Register_ToEmployeeSelf.ToString())) { Log.Info(GlobalParams.StartMail); string mEmail = GetEmail(newEmployee.Email); string firstNmae = newEmployee.FirstName; string userName = newEmployee.Email.Replace(GlobalParams.AdventMail, "").ToLower(); EmailContent ec = EmailConfig.EmailTemplates[EmailType.Register_ToEmployeeSelf.ToString()]; // {0} - First Name // {1} - Account (User Name) // {2} - Password // {3} - CARSAddress string emailBody = string.Format(ec.Body, firstName, userName, CryptographyStuff.AES_DecryptString(newEmployee.Password), EmailConfig.CARSAddress); SendMail sender = new SendMail(mEmail, null, EmailConfig.EmailAccount, emailBody, ec.Title, EmailConfig.Password, EmailConfig.Host); sender.Send(); Log.Info(GlobalParams.EndMail); } else { Log.Warn(GlobalParams.MailError); throw new Exception(GlobalParams.MailError); } } catch (SqlException sqlEx) { if (sqlEx.Message.Contains("UniqueKeyEmail")) // try to add duplicate account { Log.Warn("Try to register a duplicate account." + Environment.NewLine + email); throw new Exception(email + " was registered already." + Environment.NewLine + "Try another email account or contact with Administrator."); } else { throw sqlEx; } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndAddEmpl); return(newEmployee); }
void Login_GetReportBugAddressCompleted(object sender, GetReportBugAddressCompletedEventArgs e) { ClientInstance.ReportBugAddress = e.Result; isLoading = false; if (CarsConfig.Instance().DoSavePW) { LoginInfo loginInfo = CarsConfig.Instance().LoadLoginInfo(); userNameTxtBox.Text = loginInfo.UserName.Replace(emailSuffix.Content.ToString(), ""); passwordTxtBox.Password = loginInfo.Password; if (CarsConfig.Instance().DoAutoLogin) { ClientInstance.Get().LoginAsync(loginInfo.UserName, CryptographyStuff.AES_EncryptString(loginInfo.Password)); } } }
private void client_GetAllEmployeesCompleted(object sender, GetAllEmployeesCompletedEventArgs e) { Logger.Instance().Log(MessageType.Information, "Get All Employee Completed"); if (ErrorHandler.Handle(e.Error)) { return; } List <Employee> employees = new List <Employee>(); if (e.Result != null) { employees = e.Result.ToList <Employee>(); } else { Logger.Instance().Log(MessageType.Error, "Result is NULL"); } source.Clear(); for (int i = 0; i < employees.Count; i++) { employees[i].Password = CryptographyStuff.AES_DecryptString(employees[i].Password); User user = new User(employees[i]); user.Index = i + 1; source.Add(user); } records.ItemsSource = null; records.ItemsSource = source; records.SelectedIndex = currentSelectIndex; records.LoadingRow += new EventHandler <DataGridRowEventArgs>(records_LoadingRow); //ClientInstance.HideSpinner(); }
/// <summary> /// Forget password /// </summary> /// <param name="email">Email address to receive password</param> /// <returns>True or false</returns> public bool ForgetPassword(string email) { Log.Info(GlobalParams.StartForgetPwd); try { EmailConfig.SetRootPath(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath); Employee employee = EmployeeBLL.GetEmployeeByEmail(email); if (employee != null && EmailConfig.EmailTemplates.ContainsKey(EmailType.ForgetPassword.ToString())) { email = GetEmail(email); EmailContent emailContent = EmailConfig.EmailTemplates[EmailType.ForgetPassword.ToString()]; // {0} - First Name // {1} - Password // {2} - CARSAddress string emailBody = string.Format(emailContent.Body, employee.FirstName, CryptographyStuff.AES_DecryptString(employee.Password), EmailConfig.CARSAddress); SendMail sender = new SendMail(email, null, EmailConfig.EmailAccount, emailBody, emailContent.Title, EmailConfig.Password, EmailConfig.Host); sender.Send(); } else { Log.Warn(GlobalParams.PwdError); return(false); } } catch (Exception ex) { Log.Exception(ex.StackTrace); Log.Exception(ex.Message); throw ex; } Log.Info(GlobalParams.EndForgetPwd); return(true); }
void PersonalInformation_CheckSupervisorValidationCompleted(object sender, CheckSupervisorValidationCompletedEventArgs e) { Logger.Instance().Log(MessageType.Information, "Check Supervisor Validation Completed"); if (ErrorHandler.Handle(e.Error)) { return; } if (!e.Result) { string message = "You cannot selete one of {0} team members as {0} supervisor."; if (baseInfoControl.CurrentPgae == CARSPage.PersonalInfo) { message = string.Format(message, "your"); } else if (baseInfoControl.CurrentPgae == CARSPage.EmployeeInfo) { message = string.Format(message, currentUser.FirstName + "'s"); } Message.Warning(message); return; } currentUser.FirstName = baseInfoControl.firstName.Text.Trim(); currentUser.MiddleName = baseInfoControl.middleName.Text.Trim(); currentUser.LegalName = baseInfoControl.legalName.Text.Trim(); currentUser.LastName = baseInfoControl.lastName.Text.Trim(); currentUser.Gender = (Sex)Enum.Parse(typeof(Sex), ((ComboBoxItem)baseInfoControl.gender.SelectedItem).Content.ToString(), false); currentUser.ServiceYears = float.Parse(baseInfoControl.serviceYears.Text); currentUser.DateOfHire = baseInfoControl.dateOfHire.SelectedDate.HasValue ? baseInfoControl.dateOfHire.SelectedDate.Value : currentUser.DateOfHire; currentUser.Supervisor = baseInfoControl.supervisor.SelectedItem != null ? ((User)baseInfoControl.supervisor.SelectedItem).Employee : currentUser.Supervisor; if (baseInfoControl.password1.Password != "") { currentUser.Password = baseInfoControl.password1.Password; } currentUser.Phone = baseInfoControl.phone.Text.Trim(); currentUser.Mobile = baseInfoControl.mobile.Text.Trim(); currentUser.Employee.IsAdmin = baseInfoControl.isAdministrator.IsChecked.HasValue ? baseInfoControl.isAdministrator.IsChecked.Value : currentUser.Employee.IsAdmin; currentUser.Employee.IsActive = baseInfoControl.isActive.IsChecked.HasValue ? baseInfoControl.isActive.IsChecked.Value : currentUser.Employee.IsActive; currentUser.Employee.IsManager = baseInfoControl.isSupervisor.IsChecked.HasValue ? baseInfoControl.isSupervisor.IsChecked.Value : currentUser.Employee.IsManager; currentUser.Employee.CostCenter = baseInfoControl.costCenter.Text.Trim(); currentUser.Employee.EmployeeNum = baseInfoControl.employeeID.Text == "" ? 0 : int.Parse(baseInfoControl.employeeID.Text.Trim()); string supervisorEmail = currentUser.Supervisor != null ? currentUser.Supervisor.Email : ""; ClientInstance.Get().UpdateEmployeeAsync(currentUser.Employee.PKEmployeeID.ToString(), currentUser.Email, currentUser.FirstName, currentUser.MiddleName, currentUser.LastName, currentUser.LegalName, currentUser.Gender, currentUser.ServiceYears, currentUser.DateOfHire, supervisorEmail, CryptographyStuff.AES_EncryptString(currentUser.Password), currentUser.Phone, currentUser.Mobile, currentUser.Employee.IsAdmin, currentUser.Employee.IsActive, currentUser.Employee.IsManager, currentUser.Employee.CostCenter, currentUser.Employee.EmployeeNum); }