//the button that checks if all fields of the create user panel are filled and then calls the method that adds a user to the database private void buttonCreateUser_Click(object sender, EventArgs e) { ConUser userObject = new ConUser(); //check if all the fields are filled bool check = userObject.checkFields(textBoxUserFirstName.Text, textBoxUserLastName.Text, comboBoxTypeOfUser.Text, textBoxUserEmail.Text, textBoxUserPhoneNumber.Text, comboBoxUserLocation.Text); if (check == false) { lblCreateUserError.Text = "Please fill in all the information"; } else { //insert user into database string createUserFeedback = userObject.InsertUser(textBoxUserFirstName.Text, textBoxUserLastName.Text, comboBoxTypeOfUser.Text, textBoxUserEmail.Text, textBoxUserPhoneNumber.Text, comboBoxUserLocation.Text, checkBoxUserSendPassword.Checked); if (createUserFeedback == "Account created succesfully!") { lblCreateUserError.Text = ""; btnUser.PerformClick(); lblCreateUserSucces.Text = createUserFeedback; } else { lblCreateUserError.Text = createUserFeedback; } } }
protected void FormsAuthentication_OnAuthenticate(Object sender, FormsAuthenticationEventArgs e) { if (FormsAuthentication.CookiesSupported == true) { if (Request.Cookies[FormsAuthentication.FormsCookieName] != null) { try { string token = FormsAuthentication.Decrypt(Request.Cookies[FormsAuthentication.FormsCookieName].Value).Name; string roles = string.Empty; // token = (string) Session["token"]; UserModel user = APIAccount.GetUserProfile(token, out string error); roles = ConUser.CovertRoletoRoleString(user.Role); if (user != null && token != null) { } e.User = new System.Security.Principal.GenericPrincipal( new System.Security.Principal.GenericIdentity(user.Fullname, "Forms"), roles.Split(';')); } catch (Exception) { var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext); Response.Redirect(urlHelper.Action("Login", "Account")); } } } }
private void btnSubmitNewPswd_Click(object sender, EventArgs e) { string password = txtNewPswd.Text; string rptPassword = txtRepeatPswd.Text; //check if the new password is valid if (string.IsNullOrWhiteSpace(password) || string.IsNullOrWhiteSpace(rptPassword)) { MessageBox.Show("Fields can't be empty"); } else if (password != rptPassword) { MessageBox.Show("Passwords do not match"); } else { //update password Login login = new Login(); ConUser conUser = new ConUser(); string hashedpswd = conUser.HashPassword(password); login.ConUpdatePassword(email, hashedpswd); pnlforgotpswd.Hide(); pnlCode.Hide(); pnlNewPswd.Hide(); MessageBox.Show("Password updated"); } }
private void btnLogin_Click(object sender, EventArgs e) { Login login = new Login(); ConUser conUser = new ConUser(); email = txtEmail.Text; string password = txtPassword.Text; string hashedpswd = conUser.HashPassword(password); BsonDocument user = login.CheckUser(email, password); if (user != null) { if (user.GetElement("Password").Value.ToString() == hashedpswd) { // makes the remember me function work if (chkremember.Checked == true) { Properties.Settings.Default.Name = txtEmail.Text; Properties.Settings.Default.Password = password; Properties.Settings.Default.Save(); } if (chkremember.Checked == false) { Properties.Settings.Default.Name = ""; Properties.Settings.Default.Password = ""; Properties.Settings.Default.Save(); } // add a "session" of the user that is logged in, that way you can access his or her information in the main program ConSession session = new ConSession(); session.AddSession(user.GetElement("FirstName").Value.ToString(), user.GetElement("Email").Value.ToString(), ObjectId.Parse(user.GetElement("_id").Value.ToString())); this.Hide(); // checks if the user is a service desk employee or a employee if (int.Parse(user.GetElement("Role").Value.ToString()) == 0) { Employee employee = new Employee(); employee.Show(); } else { Form1 form1 = new Form1(); form1.Show(); } } else { MessageBox.Show("Email and Password combination is not valid"); } } else { MessageBox.Show("This user doesn't exist"); } }
//a method that receives all users and puts them in the listview private void GetAllUsers() { userItems.Clear(); listUsers.Items.Clear(); ConUser ConUserObject = new ConUser(); //calling the method that retrieves all users from the database List <ModUser> users = ConUserObject.GetAllUsers(); int id = 1; foreach (ModUser user in users) { //adding every user to the listview ListViewItem lvItem = new ListViewItem(new[] { id.ToString(), user.Email, user.FirstName, user.LastName, user.NrOfTickets.ToString() }); ModUser modUser = new ModUser { Id = id, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, NrOfTickets = user.NrOfTickets }; userItems.Add(modUser); listUsers.Items.Add(lvItem); id++; } }