Exemplo n.º 1
0
        public void AddMember()
        {
            ValidateEmail ve = new ValidateEmail();

            if (name.Length == 0)
            {
                MessageBox.Show("Please enter a name.");
            }
            else if (!ve.IsValidEmail(email))
            {
                MessageBox.Show("Please enter a valid email.");
            }
            else if (phoneNumber.Length < 5)
            {
                MessageBox.Show("Please enter a valid phone number");
            }
            else if (file.members.FirstOrDefault(m => m.name.Equals(name)) != null)
            {
                MessageBox.Show("Member already exists under this name. If this is a new person, add a middle initial or department.");
            }
            else
            {
                file.members.Add(new LunchClubMember {
                    name = this.name, phoneNumber = this.phoneNumber, email = this.email, diet = this.diet
                });
                file.Save();
                OnRequestClose(null);
            }
        }
Exemplo n.º 2
0
        public Tuple <bool, string> UpdateEmail(string emailAddress)
        {
            ValidateEmail v = new ValidateEmail();

            if (!v.IsValidEmail(emailAddress))
            {
                return(Tuple.Create(false, "Invalid email address. "));
            }
            if (_context.USER_TABLE.Where(u => u.email == emailAddress).Count() > 0)
            {
                return(Tuple.Create(false, "This email is taken. Your email must be unique. "));
            }
            if (_context.AspNetUsers.Where(u => u.Email == emailAddress).Count() > 0)
            {
                return(Tuple.Create(false, "This email is taken. Your email must be unique. "));
            }

            _user.email    = emailAddress;
            _aspUser.Email = emailAddress;
            try
            {
                _context.SaveChanges();
                return(Tuple.Create(true, "Email updated successfully. "));
            }
            catch (Exception e)
            {
                return(Tuple.Create(false, "Failed to update email address. " + e.ToDetailedString()));
            }
        }
Exemplo n.º 3
0
 public void AddMember()
 {
     ValidateEmail ve = new ValidateEmail();
     if (name.Length == 0)
     {
         MessageBox.Show("Please enter a name.");
     }
     else if (!ve.IsValidEmail(email))
     {
         MessageBox.Show("Please enter a valid email.");
     }
     else if (phoneNumber.Length < 5)
     {
         MessageBox.Show("Please enter a valid phone number");
     }
     else if (file.members.FirstOrDefault(m => m.name.Equals(name)) != null)
     {
         MessageBox.Show("Member already exists under this name. If this is a new person, add a middle initial or department.");
     }
     else
     {
         file.members.Add(new LunchClubMember { name = this.name, phoneNumber = this.phoneNumber, email = this.email, diet = this.diet });
         file.Save();
         OnRequestClose(null);
     }
 }
Exemplo n.º 4
0
        public void EditMember()
        {
            ValidateEmail ve = new ValidateEmail();

            if (name.Length == 0)
            {
                MessageBox.Show("Please enter a name.");
            }
            else if (!ve.IsValidEmail(email))
            {
                MessageBox.Show("Please enter a valid email.");
            }
            else if (phoneNumber.Length < 5)
            {
                MessageBox.Show("Please enter a valid phone number");
            }
            else
            {
                LunchClubMember em = file.members.First(m => m.name.Equals(editMember.name));
                em.name        = name;
                em.email       = email;
                em.phoneNumber = phoneNumber;
                em.diet        = diet;

                file.Save();
                OnRequestClose(null);
            }
        }
Exemplo n.º 5
0
 public string MailCheck(string input)
 {
     // Validate email
     if (ValidateEmail.IsValidEmail(input))
     {
         return(RegisterModel.CheckMail(SqlInjection.SafeSqlLiteral(StringManipulation.ToLowerFast(input))) > 0
             ? "Deze email is al bezet"
             : "Deze email is nog niet bezet");
     }
     return("Dit is geen geldig email adres");
 }
Exemplo n.º 6
0
        public ActionResult CreateUser(UserViewModel userViewModel, HttpPostedFileBase userPicture = null)
        {
            string         userPictureFilePath = null;
            IdentityResult result = null;

            if (ModelState.IsValid)
            {
                if (userPicture != null)
                {
                    //Save uploaded file to path of "~/Images/UserPicture"
                    int    splitIndex  = userPicture.ContentType.LastIndexOf(@"/");
                    string newFileName = Guid.NewGuid().ToString() + "." + userPicture.ContentType.Substring(++splitIndex);
                    userPictureFilePath = Path.Combine(Server.MapPath("/Images/UserPicture"), newFileName);
                    if (!Directory.Exists(Server.MapPath("/Images/UserPicture")))
                    {
                        Directory.CreateDirectory(Server.MapPath("/Images/UserPicture"));
                    }
                    userPicture.SaveAs(userPictureFilePath);
                }
                else
                {
                    userPictureFilePath = Path.Combine(Server.MapPath("/Images"), "defaultUser.jpg");
                }
                if (!ValidateEmail.IsValidEmail(userViewModel.Email))
                {
                    ModelState.AddModelError("Email", "邮箱地址无效");
                    if (!string.IsNullOrEmpty(userPictureFilePath) && !userPictureFilePath.Contains("defaultUser.jpg"))
                    {
                        System.IO.File.Delete(userPictureFilePath);
                    }
                    return(View(userViewModel));
                }
                if (!ValidateEmail.IsValidEmail(userViewModel.DirectManagerEmail))
                {
                    ModelState.AddModelError("DirectManagerEmail", "邮箱地址无效");
                    if (!string.IsNullOrEmpty(userPictureFilePath) && !userPictureFilePath.Contains("defaultUser.jpg"))
                    {
                        System.IO.File.Delete(userPictureFilePath);
                    }
                    return(View(userViewModel));
                }
                User user = new User();
                user.FullName           = userViewModel.FullName;
                user.UserName           = userViewModel.UserName;
                user.Email              = userViewModel.Email;
                user.Title              = userViewModel.Title;
                user.Department         = userViewModel.Department;
                user.DirectManagerEmail = userViewModel.DirectManagerEmail;
                user.HireDate           = userViewModel.HireDate;
                user.IdentityNumber     = userViewModel.IdentityNumber;
                user.ContactAddress     = userViewModel.ContactAddress;
                user.PhoneNumber        = userViewModel.ContactPhone;
                user.UserIconURL        = userPictureFilePath;
                if (string.IsNullOrEmpty(userViewModel.Password))
                {
                    result = UserManager.Create(user);
                }
                else
                {
                    result = UserManager.Create(user, userViewModel.Password);
                }

                if (result.Succeeded)
                {
                    return(RedirectToAction("GetUsers", "Account"));
                }
                else
                {
                    foreach (var error in result.Errors)
                    {
                        ModelState.AddModelError("", error);
                    }
                }
                //Clean before created file if encounter any errors
                if (!string.IsNullOrEmpty(userPictureFilePath) && !userPictureFilePath.Contains("defaultUser.jpg"))
                {
                    System.IO.File.Delete(userPictureFilePath);
                }
            }

            return(View(userViewModel));
        }
Exemplo n.º 7
0
        /// <summary>
        /// Function AddLocation to create the new location
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>NA</returns>
        /// <createdBy></createdBy>
        /// <createdOn>May-27,2016</createdOn>
        private void AddLocation(object obj)
        {
            try
            {
                string errMsg = string.Empty;
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));

                if (!string.IsNullOrEmpty(LocationName) && (!string.IsNullOrEmpty(LocationName)))
                {
                    if (!string.IsNullOrEmpty(DescriptionLocType) && (!string.IsNullOrEmpty(DescriptionLocType)))
                    {
                        if (!string.IsNullOrEmpty(DescriptionLocSubType) && (!string.IsNullOrEmpty(DescriptionLocSubType)))
                        {
                            if (!string.IsNullOrEmpty(Zip) && (!string.IsNullOrEmpty(Zip)))
                            {
                                ValidateEmail emailValidation = new ValidateEmail();
                                bool          isValid         = emailValidation.IsValidEmail(Email);
                                if (isValid || string.IsNullOrEmpty(Email))
                                {
                                    // creating the object of service property and setting the values
                                    AppWorksService.Properties.LocationList objAddLocationProp = new AppWorksService.Properties.LocationList();

                                    objAddLocationProp.ParentRecordID       = Convert.ToInt32(Application.Current.Resources["CustomerAdminID"]);
                                    objAddLocationProp.ParentRecordTable    = "Customer";
                                    objAddLocationProp.LocationName         = LocationName;
                                    objAddLocationProp.LocationShortName    = LocationShortName;
                                    objAddLocationProp.LocationType         = DescriptionLocType;
                                    objAddLocationProp.LocationSubType      = DescriptionLocSubType;
                                    objAddLocationProp.CustomerLocationCode = string.Empty;
                                    objAddLocationProp.AddressLine1         = AddressLine1;
                                    objAddLocationProp.AddressLine2         = AddressLine2;
                                    objAddLocationProp.City      = City;
                                    objAddLocationProp.State     = State;
                                    objAddLocationProp.Zip       = Zip;
                                    objAddLocationProp.Country   = Country;
                                    objAddLocationProp.MainPhone = MainPhone;
                                    objAddLocationProp.FaxNumber = FaxNumber;
                                    objAddLocationProp.PrimaryContactFirstName = FirstName;
                                    objAddLocationProp.PrimaryContactLastName  = LastName;
                                    objAddLocationProp.PrimaryContactPhone     = Phone;
                                    objAddLocationProp.PrimaryContactExtension = Extension;
                                    objAddLocationProp.PrimaryContactCellPhone = ContactCellPhone;
                                    objAddLocationProp.PrimaryContactEmail     = Email;

                                    objAddLocationProp.AlternateContactFirstName = AlternateContactFirstName;
                                    objAddLocationProp.AlternateContactLastName  = AlternateContactLastName;
                                    objAddLocationProp.AlternateContactPhone     = AlternateContactPhone;
                                    objAddLocationProp.AlternateContactExtension = OtherContactExtension;
                                    objAddLocationProp.AlternateContactCellPhone = AlternateContactCellPhone;
                                    objAddLocationProp.AlternateContactEmail     = AlternateContactEmail;
                                    objAddLocationProp.OtherPhone1Description    = OtherPhone1Description;

                                    objAddLocationProp.OtherPhone1            = OtherPhone1;
                                    objAddLocationProp.OtherPhone2Description = OtherPhone2Description;
                                    objAddLocationProp.OtherPhone2            = OtherPhone2;
                                    objAddLocationProp.RecordStatus           = RecordStatus;
                                    objAddLocationProp.CreationDate           = CreationDate;
                                    objAddLocationProp.CreatedBy   = CreatedBy;
                                    objAddLocationProp.UpdatedDate = UpdatedDate;
                                    objAddLocationProp.UpdatedBy   = updatedBy;
                                    objAddLocationProp.UpdatedBy   = InternalId;

                                    // Call service function to add a new location
                                    int data = _serviceInstance.AddLocation(objAddLocationProp);

                                    if (data > 0)
                                    {
                                        LocationId = data;
                                        LocationDeligate.SetValueMethodUpdateCmd("UpdateList");
                                        MessageBox.Show(Resources.msgInsertedSuccessfully);
                                        var window = obj as Window;
                                        if (window != null)
                                        {
                                            window.Close();
                                        }
                                    }
                                }
                                else
                                {
                                    //ClsValidationPopUp.ErrMsgUserPin = Resources.ErrorEmptyPin
                                    errMsg = Resources.ErrorEmail;
                                    AutoLogOffPopup objAutoLogOffPopup = new AutoLogOffPopup(errMsg);
                                    objAutoLogOffPopup.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                                    objAutoLogOffPopup.ShowDialog();
                                }
                            }
                            else
                            {
                                MessageBox.Show(Resources.msgLocationZipReq);
                            }
                        }
                        else
                        {
                            MessageBox.Show(Resources.msgLocationSubTypeReq);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Resources.msgLocationTypeReq);
                    }
                }
                else
                {
                    MessageBox.Show(Resources.msgLocationNameReq);
                }
            }
            catch (Exception ex)
            {
                LogHelper.LogErrorToDb(ex);
                bool displayErrorOnUI = false;
                CommonSettings.logger.LogError(this.GetType(), ex);
                if (displayErrorOnUI)
                {
                    throw;
                }
            }

            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }
Exemplo n.º 8
0
        public void shouldReturnFalse(string value)
        {
            var result = _validateEmail.IsValidEmail(value);

            Assert.False(result);
        }
Exemplo n.º 9
0
 public string MailCheck(string input)
 {
     return(ValidateEmail.IsValidEmail(input) ? "true" : "false");
 }
Exemplo n.º 10
0
        /// <summary>
        /// Function to Save/Update a particular user.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns>NA</returns>
        /// <createdBy></createdBy>
        /// <createdOn>May-27,2016</createdOn>
        public void Save_Click(object obj)
        {
            try
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgStart, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));

                WebPortalUserList objUserProp = new WebPortalUserList();

                if (UserID != null && UserID > 0)
                {
                    objUserProp.userID = (int)UserID;
                }

                objUserProp.username    = UserName;
                objUserProp.password    = Password;
                objUserProp.firstname   = FirstName;
                objUserProp.lastname    = LastName;
                objUserProp.email       = Email;
                objUserProp.phone       = Phone;
                objUserProp.isActive    = IsActive;
                objUserProp.isSuperUser = 0;
                objUserProp.lastLogin   = DateTime.Now;
                if (IsAction == Resources.ActionSave)
                {
                    objUserProp.whoCreated  = Application.Current.Properties["LoggedInUserName"].ToString();
                    objUserProp.dateCreated = DateTime.Now;
                }
                else if (IsAction == Resources.ActionUpdate)
                {
                    objUserProp.whoModified  = Application.Current.Properties["LoggedInUserName"].ToString();
                    objUserProp.dateModified = DateTime.Now;
                }

                if (!string.IsNullOrEmpty(UserName))
                {
                    if (!string.IsNullOrEmpty(Password))
                    {
                        if (!string.IsNullOrEmpty(Email))
                        {
                            ValidateEmail emailValidation = new ValidateEmail();
                            bool          isValid         = emailValidation.IsValidEmail(Email);
                            if (isValid)
                            {
                                bool checkDuplicateUserName = _serviceInstance.CheckDuplicateEmail(Email);
                                bool checkDuplicateEmailID  = _serviceInstance.CheckDuplicatePortalUserName(UserName);
                                bool isSuccessfull          = false;
                                if (IsAction == Resources.ActionSave)
                                {
                                    if (!checkDuplicateUserName)
                                    {
                                        if (!checkDuplicateEmailID)
                                        {
                                            isSuccessfull = _serviceInstance.InsertUpdateUser(objUserProp, ListCustomer.ToArray(), ListModule.ToArray(), ListRole.ToArray(), ListGroup.ToArray());
                                        }
                                        else
                                        {
                                            MessageBox.Show(Resources.MsgDuplicateUserName);
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show(Resources.MsgDuplicateEmailID);
                                    }
                                }
                                else if (IsAction == Resources.ActionUpdate)
                                {
                                    isSuccessfull = _serviceInstance.InsertUpdateUser(objUserProp, ListCustomer.ToArray(), ListModule.ToArray(), ListRole.ToArray(), ListGroup.ToArray());
                                }

                                if (isSuccessfull)
                                {
                                    if (IsAction == Resources.ActionUpdate)
                                    {
                                        MessageBox.Show(Resources.msgUpdatedSuccessfully);
                                    }
                                    else if (IsAction == Resources.ActionSave)
                                    {
                                        MessageBox.Show(Resources.msgInsertedSuccessfully);
                                    }
                                    ClearUserInfo();
                                    CurrentView   = new WebPortalUsersView();
                                    IsVisibleInfo = Resources.MsgHidden;
                                    IsModify      = true;
                                    IsButtonPanel = Resources.MsgHidden;
                                    IsAction      = Resources.ActionSave;
                                    LoadUsers(null);
                                    View_Click(null);
                                    AcceptChanges();
                                }
                            }
                            else
                            {
                                MessageBox.Show(Resources.ErrorEmail);
                            }
                        }
                        else
                        {
                            MessageBox.Show(Resources.ReqEmail);
                        }
                    }
                    else
                    {
                        MessageBox.Show(Resources.ReqPassword);
                    }
                }
                else
                {
                    MessageBox.Show(Resources.ReqrUserName);
                }
            }
            catch (Exception ex)
            {
                CommonSettings.logger.LogError(this.GetType(), ex);
            }
            finally
            {
                CommonSettings.logger.LogInfo(typeof(string), string.Format(CultureInfo.InvariantCulture, Resources.loggerMsgEnd, DateTime.Now.ToShortDateString(), DateTime.Now.ToShortTimeString(), MethodBase.GetCurrentMethod().Name));
            }
        }
Exemplo n.º 11
0
        public bool AddAccount()
        {
            // Run model through sql prevention and save them to vars
            var mail = SqlInjection.SafeSqlLiteral(StringManipulation.ToLowerFast(Email));
            var salt = Crypt.GetRandomSalt();

            // Validate email using regex since HTML5 validation doesn't handle some cases
            if (!ValidateEmail.IsValidEmail(mail))
            {
                return(false);
            }

            // MySQL query
            const string countStatement = "SELECT COUNT(*) " +
                                          "FROM gebruikers " +
                                          "WHERE Email = ?";

            using (var empConnection = DatabaseConnection.DatabaseConnect())
            {
                int count;
                using (var countCommand = new MySqlCommand(countStatement, empConnection))
                {
                    // Bind parameters
                    countCommand.Parameters.Add("Email", MySqlDbType.VarChar).Value = mail;
                    try
                    {
                        DatabaseConnection.DatabaseOpen(empConnection);
                        // Execute command
                        count = Convert.ToInt32(countCommand.ExecuteScalar());
                    }
                    catch (MySqlException)
                    {
                        // MySqlException bail out
                        return(false);
                    }
                    finally
                    {
                        // Make sure to close the connection
                        DatabaseConnection.DatabaseClose(empConnection);
                    }
                }

                if (count > 0)
                {
                    // Email already in the database bail out
                    return(false);
                }

                // Insert user in the database
                const string insertStatement = "INSERT INTO gebruikers " +
                                               "(Email, Password, Salt) " +
                                               "VALUES (?, ?, ?)";

                using (var insertCommand = new MySqlCommand(insertStatement, empConnection))
                {
                    // Bind parameters
                    insertCommand.Parameters.Add("Email", MySqlDbType.VarChar).Value    = mail;
                    insertCommand.Parameters.Add("Password", MySqlDbType.VarChar).Value = Crypt.HashPassword(Password, salt);
                    insertCommand.Parameters.Add("Salt", MySqlDbType.VarChar).Value     = salt;

                    try
                    {
                        DatabaseConnection.DatabaseOpen(empConnection);
                        // Execute command
                        insertCommand.ExecuteNonQuery();
                        return(true);
                    }
                    catch (MySqlException)
                    {
                        // MySqlException bail out
                        return(false);
                    }
                    finally
                    {
                        // Make sure to close the connection
                        DatabaseConnection.DatabaseClose(empConnection);
                    }
                }
            }
        }
Exemplo n.º 12
0
        public void EditMember()
        {
            ValidateEmail ve = new ValidateEmail();
            if (name.Length == 0)
            {
                MessageBox.Show("Please enter a name.");
            }
            else if (!ve.IsValidEmail(email))
            {
                MessageBox.Show("Please enter a valid email.");
            }
            else if (phoneNumber.Length < 5)
            {
                MessageBox.Show("Please enter a valid phone number");
            }
            else
            {

                LunchClubMember em = file.members.First(m => m.name.Equals(editMember.name));
                em.name = name;
                em.email = email;
                em.phoneNumber = phoneNumber;
                em.diet = diet;

                file.Save();
                OnRequestClose(null);
            }
        }
Exemplo n.º 13
0
 public string MailCheck(string input)
 {
     return(ValidateEmail.IsValidEmail(input) ? "valid" : String.Empty);
 }
Exemplo n.º 14
0
 public bool SaveEmail(string input)
 {
     return(ValidateEmail.IsValidEmail(input) && ContactPluginSettingsModel.SaveEmail(input));
 }
Exemplo n.º 15
0
        // <summary>
        // Add account to the database and send a mail to the user
        // </summary>
        public bool AddAccount()
        {
            // Run model through sql prevention and save them to vars
            var firstName = SqlInjection.SafeSqlLiteral(Firstname);
            var affix     = SqlInjection.SafeSqlLiteral(Affix);
            var lastName  = SqlInjection.SafeSqlLiteral(Lastname);
            var mail      = SqlInjection.SafeSqlLiteral(StringManipulation.ToLowerFast(Mail));
            var pepper    = Crypt.GetRandomSalt();

            // Validate email using regex since HTML5 validation doesn't handle some cases
            if (!ValidateEmail.IsValidEmail(mail))
            {
                return(false);
            }

            // MySQL query
            const string countStatement = "SELECT COUNT(*) " +
                                          "FROM meok2_bibliotheek_gebruikers " +
                                          "WHERE email = ?";

            using (var empConnection = DatabaseConnection.DatabaseConnect())
            {
                int count;
                using (var countCommand = new MySqlCommand(countStatement, empConnection))
                {
                    // Bind parameters
                    countCommand.Parameters.Add("email", MySqlDbType.VarChar).Value = mail;
                    try
                    {
                        DatabaseConnection.DatabaseOpen(empConnection);
                        // Execute command
                        count = Convert.ToInt32(countCommand.ExecuteScalar());
                    }
                    catch (MySqlException)
                    {
                        // MySqlException bail out
                        return(false);
                    }
                    finally
                    {
                        // Make sure to close the connection
                        DatabaseConnection.DatabaseClose(empConnection);
                    }
                }

                if (count > 0)
                {
                    // Email already in the database bail out
                    return(false);
                }

                // Insert user in the database
                const string insertStatement = "INSERT INTO meok2_bibliotheek_gebruikers " +
                                               "(voornaam, tussenvoegsel, achternaam, email, pepper) " +
                                               "VALUES (?, ?, ?, ?, ?)";

                using (var insertCommand = new MySqlCommand(insertStatement, empConnection))
                {
                    // Bind parameters
                    insertCommand.Parameters.Add("voornaam", MySqlDbType.VarChar).Value =
                        Crypt.StringEncrypt((firstName), pepper);
                    insertCommand.Parameters.Add("tussenvoegsel", MySqlDbType.VarChar).Value =
                        Crypt.StringEncrypt((affix), pepper);
                    insertCommand.Parameters.Add("achternaam", MySqlDbType.VarChar).Value =
                        Crypt.StringEncrypt((lastName), pepper);
                    insertCommand.Parameters.Add("email", MySqlDbType.VarChar).Value  = mail;
                    insertCommand.Parameters.Add("pepper", MySqlDbType.VarChar).Value = pepper;

                    try
                    {
                        DatabaseConnection.DatabaseOpen(empConnection);
                        // Execute command
                        insertCommand.ExecuteNonQuery();

                        // Send mail bail out if mail fails
                        return(Message.SendMail(firstName, Mail) == "False");
                    }
                    catch (MySqlException)
                    {
                        // MySqlException bail out
                        return(false);
                    }
                    finally
                    {
                        // Make sure to close the connection
                        DatabaseConnection.DatabaseClose(empConnection);
                    }
                }
            }
        }