Пример #1
0
        public ActionResult Login(ContactInfo contactInfo)
        {
            if (ModelState.IsValid)
            {
                int errors = 0;

                if (!db.VerifyName(contactInfo.Name))
                {
                    errors++;
                    contactInfo.LoginNameErrorMsg = "Navnet er ugyldigt.";
                    return(View(contactInfo));
                }

                if (!db.VerifyNumber(contactInfo.Number))
                {
                    errors++;
                    contactInfo.LoginNumberErrorMsg = "Telefonnummeret er ugyldigt.";
                    return(View(contactInfo));
                }

                if (!db.VerifyEmail(contactInfo.Email))
                {
                    errors++;
                    contactInfo.LoginEmailErrorMsg = "E-mailadressen er ugyldig.";
                    return(View(contactInfo));
                }

                if (errors == 0)
                {
                    var resultContactInfo = db.GetContactInfoByStrings(contactInfo.Name, contactInfo.Number, contactInfo.Email);
                    if (resultContactInfo != null)
                    {
                        Session["LoggedContactId"] = resultContactInfo.Id.ToString();
                        return(RedirectToAction("Index", "Auction"));
                    }
                }
            }
            return(View(contactInfo));
        }
Пример #2
0
        //------------------------------ EVENTHANDLERS --------------------------------------------------------

        /*
         * Validates userinput and opens
         * a new MainWindow sending the
         * userinput as arguments if
         * validation is succeeded.
         * If validation fails, errormessage(s)
         * are sent to the user at this window.
         */
        private void LoginButton_Click(object sender, RoutedEventArgs e)
        {
            // Hide errorlabels to reevaluate validation.
            HideErrorLabels();

            string name   = TxtBoxUserName.Text;
            string number = TxtBoxUserNumber.Text;
            string email  = TxtBoxUserEmail.Text;

            int errorCounter = 0;

            if (name == null || name == "Navn" || name == "" || !_context.VerifyName(name) || name.Length < 2 || name.Length > 40)
            {
                errorCounter++;
                if (name.Length < 2 || name.Length > 40)
                {
                    nameErrorLabel.Content = "Navnet skal indeholde 2 - 40 tegn.";
                }
                else if (name != "Navn" && name != "" && !_context.VerifyName(name))
                {
                    nameErrorLabel.Content = "Navnet er ugyldigt.";
                }
                else
                {
                    nameErrorLabel.Content = "Indtast venligst dit navn.";
                }
                nameErrorLabel.Visibility = Visibility.Visible;
            }

            if (number == null || number == "Telefonnummer" || number == "" || !_context.VerifyNumber(number) || number.Length < 8 || number.Length > 15)
            {
                errorCounter++;
                if (number.Length < 8 || number.Length > 15)
                {
                    numberErrorLabel.Content = "Telefonnummeret skal indeholde 8 - 15 tal.";
                }
                else if (number != "Telefonnummer" && number != "" && !_context.VerifyNumber(number))
                {
                    numberErrorLabel.Content = "Telefonnummeret er ugyldigt.";
                }
                else
                {
                    numberErrorLabel.Content = "Indtast venligst dit telefonnummer.";
                }
                numberErrorLabel.Visibility = Visibility.Visible;
            }

            if (email == null || email == "E-mail" || email == "" || !_context.VerifyEmail(email) || email.Length < 6)
            {
                errorCounter++;
                if (email.Length < 6)
                {
                    emailErrorLabel.Content = "E-mailadressen skal indeholde minimum 6 tegn.";
                }
                else if (email != "E-mail" && email != "" && !_context.VerifyEmail(email))
                {
                    emailErrorLabel.Content = "E-mailadressen er ugyldig.";
                }
                else
                {
                    emailErrorLabel.Content = "Indtast venligst din e-mailadresse.";
                }
                emailErrorLabel.Visibility = Visibility.Visible;
            }

            if (errorCounter == 0)
            {
                MainWindow mainWindow = new MainWindow(name, number, email);
                mainWindow.Show();
                this.Hide();
            }
        }