Exemple #1
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()));
            }
        }
Exemple #2
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);
            }
        }
        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);
            }
        }
 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);
     }
 }
 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");
 }
 private void Save_Click(object sender, EventArgs e)
 {
     if (ValidateEmail.EmailIsValid(this.emailTextBox.Text))
     {
         OnMemberAdd(new Member(this.firstNameTextBox.Text, this.lastNameTextBox.Text, this.emailTextBox.Text));
         this.Close();
     }
     else
     {
         MessageBox.Show("Invalid email!");
     }
 }
Exemple #7
0
        public User Register(string email, string firstname, string lastname, string username,
                             string question1, string answer1, string question2, string answer2, string question3, string answer3)
        {
            Database db = new Database("Books");

            try
            {
                String Pass = ValidateEmail.GeneratePassword(3, 3, 3);
                db.Command.CommandType = CommandType.StoredProcedure;
                db.Command.CommandText = "tblUserREGISTER";
                db.Command.Parameters.Add("@FirstName", SqlDbType.VarChar).Value = firstname;
                db.Command.Parameters.Add("@LastName", SqlDbType.VarChar).Value  = lastname;
                db.Command.Parameters.Add("@UserName", SqlDbType.VarChar).Value  = username;
                db.Command.Parameters.Add("@Password", SqlDbType.VarChar).Value  = Pass;
                db.Command.Parameters.Add("@Email", SqlDbType.VarChar).Value     = email;
                db.Command.Parameters.Add("@Question1", SqlDbType.VarChar).Value = question1;
                db.Command.Parameters.Add("@Answer1", SqlDbType.VarChar).Value   = answer1;
                db.Command.Parameters.Add("@Question2", SqlDbType.VarChar).Value = question2;
                db.Command.Parameters.Add("@Answer2", SqlDbType.VarChar).Value   = answer2;
                db.Command.Parameters.Add("@Question3", SqlDbType.VarChar).Value = question3;
                db.Command.Parameters.Add("@Answer3", SqlDbType.VarChar).Value   = answer3;
                DataTable dt = db.ExecuteQuery();
                if (dt.Rows.Count == 1)
                {
                    DataRow dr = dt.Rows[0];
                    base.Initialize(dr);
                    InitializeBusinessData(dr);
                    Email e = new Email();
                    e.To      = email;
                    e.Subject = "Your Password";
                    e.Body    = String.Format("Your password is {0}", dr["Password"].ToString());
                    e.Send();
                    return(this);
                }
                else
                {
                    return(null);
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemple #8
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));
        }
        private async void Login()
        {
            if (string.IsNullOrEmpty(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Debe indicar un email.", "Aceptar");

                return;
            }
            if (string.IsNullOrEmpty(this.Password))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Debe indicar una contraseña.", "Aceptar");

                return;
            }

            if (!ValidateEmail.Validate(this.Email))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Dirección de email invalida.", "Aceptar");

                this.Email = string.Empty;
                return;
            }

            this.IsRunning = true;
            this.IsEnabled = false;

            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert("Atención", "No hay conexión.", "Aceptar");

                return;
            }

            var response = await this.apiService.GetParameter <Usuario>(ValuesService.url, "api/", "Login/", "?email=" + Email + "&password="******"Error", response.Message, "Aceptar");

                Application.Current.MainPage = new NavigationPage(new LoginPage());
                this.IsRunning = false;
                this.IsEnabled = true;
                return;
            }

            Usuario usuario = new Usuario();

            usuario = (Usuario)response.Result;

            if (usuario == null || usuario.Id_usuario == 0)
            {
                this.IsRunning = false;
                this.IsEnabled = true;
                await Application.Current.MainPage.DisplayAlert("Atención", "Email o contraseña incorrecta, por favor intente nuevamente.", "Aceptar");

                this.Password = string.Empty;
                this.Email    = string.Empty;
                return;
            }

            MainViewModel mainViewModel = MainViewModel.GetInstance();

            mainViewModel.Usuario                = new Usuario();
            mainViewModel.Usuario                = usuario;
            mainViewModel.Settings               = new SettingsViewModel();
            mainViewModel.TrainingPlan           = new TrainingPlanViewModel();
            App.Current.Properties["IsLoggedIn"] = true;
            Application.Current.MainPage         = new NavigationPage(new UserMainMenuPage());

            this.IsRunning = false;
            this.IsEnabled = true;

            this.Email    = string.Empty;
            this.password = string.Empty;
        }
        // <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);
                    }
                }
            }
        }
 public bool SaveEmail(string input)
 {
     return(ValidateEmail.IsValidEmail(input) && ContactPluginSettingsModel.SaveEmail(input));
 }
Exemple #12
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));
            }
        }
 public string MailCheck(string input)
 {
     return(ValidateEmail.IsValidEmail(input) ? "true" : "false");
 }
Exemple #14
0
 public ValidateEmailTest()
 {
     _validateEmail = new ValidateEmail();
 }
Exemple #15
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));
            }
        }
Exemple #16
0
        private async void FirstRegister()
        {
            if (string.IsNullOrEmpty(nombre) || string.IsNullOrEmpty(apellido) || string.IsNullOrEmpty(email) ||
                string.IsNullOrEmpty(contraseña1) || string.IsNullOrEmpty(contraseña1))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Debe completar todos los campos.", "Aceptar");

                return;
            }
            if (contraseña1 != contraseña2)
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Las contraseñas no coinciden.", "Aceptar");

                return;
            }

            if (!ValidateEmail.Validate(this.email))
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Dirección de email invalida.", "Aceptar");

                this.Email = string.Empty;
                return;
            }
            IsRunning = true;
            IsEnabled = false;

            apiService    = new ApiService();
            this.LoadText = "Validando información, porfavor espere.";
            var connection = await apiService.CheckConnection();

            if (!connection.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "No hay conexión.", "Aceptar");

                IsRunning     = false;
                IsEnabled     = true;
                this.LoadText = string.Empty;
                return;
            }

            var response = await this.apiService.GetParameter <int>(ValuesService.url, "api/", "Login/", "?email=" + Email);

            if (!response.IsSuccess)
            {
                await Application.Current.MainPage.DisplayAlert("Error", response.Message, "Aceptar");

                Application.Current.MainPage = new NavigationPage(new LoginPage());
                IsRunning     = false;
                IsEnabled     = true;
                this.LoadText = string.Empty;
                return;
            }

            int id_usuario = (int)response.Result;

            if (id_usuario > 0)
            {
                await Application.Current.MainPage.DisplayAlert("Atención", "Ya existe un usuario con esta dirección de email, porfavor intenta con una diferente.", "Aceptar");

                IsRunning     = false;
                IsEnabled     = true;
                this.Email    = string.Empty;
                this.LoadText = string.Empty;
                return;
            }

            objUsuario.Nombre   = nombre;
            objUsuario.Apellido = apellido;
            objUsuario.Email    = email;
            objUsuario.Password = contraseña1;
            SendNewUsuario(objUsuario);
            await Application.Current.MainPage.Navigation.PushAsync(new RegisterPhysicalConditionPage());

            IsRunning     = false;
            IsEnabled     = true;
            this.LoadText = string.Empty;
        }
        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);
                    }
                }
            }
        }
        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);
            }
        }
Exemple #19
0
 public string MailCheck(string input)
 {
     return(ValidateEmail.IsValidEmail(input) ? "valid" : String.Empty);
 }