예제 #1
0
 public void loginButton_click(object parameter)
 {
     using (var db = new ParkingDBContext())
     {
         ErrorMessage = "";
         if (Username == null || Password == null)
         {
             ErrorMessage = "Unesite podatke";
             return;
         }
         foreach (User user in db.Useri)
         {
             if (user.Email == Username)
             {
                 if (user.Sifra == (Validacija.createMD5(Password)))
                 {
                     NavigationService.Navigate(typeof(View.Pocetna), user);
                 }
                 break;
             }
         }
         ErrorMessage = "Pogresna sifra ili mail";
     }
 }
        public void RegistrujSe(object parameter)
        {
            using (var db = new ParkingDBContext())
            {
                ImeErrorMessage = PrezimeErrorMessage = EmailErrorMessage = PasswordErrorMessage = RepeatPasswordErrorMessage = "";
                bool flag = false;
                if (Ime == null || Prezime == null || Password == null || RepeatPassword == null || Email == null)
                {
                    ErrorMessage = "Obavezno polje";
                    flag         = true;
                    return;
                }
                if (Ime.Length < 3 || Ime.Length > 12)
                {
                    ImeErrorMessage = "Ime mora imati minimalno 3 i maximalno 12 karaktera";
                    flag            = true;
                }
                if (Prezime.Length < 3)
                {
                    PrezimeErrorMessage = "Prezime mora imati minimalno 3 i maximalno 12 karaktera";
                    flag = true;
                }
                if (!(new EmailAddressAttribute().IsValid(Email)))
                {
                    EmailErrorMessage = "Pogresan email";
                    flag = true;
                }
                if (Password.Length < 8 || Password.Length > 24)
                {
                    PasswordErrorMessage = "Password mora imati minimalno 8 i maximalno 24 karaktera";
                    flag = true;
                }

                if (RepeatPassword != Password)
                {
                    RepeatPasswordErrorMessage = "Password se ne podudara";
                    flag = true;
                }

                if (!BoxChecked)
                {
                    CheckBoxErrorMessage = "Morate prihvatiti uslove koristenja";
                    flag = true;
                }

                if (flag)
                {
                    return;
                }
                User noviKorisnik = new User();

                noviKorisnik.Ime     = Ime;
                noviKorisnik.Prezime = Prezime;
                noviKorisnik.Email   = Email;
                noviKorisnik.Sifra   = Validacija.createMD5(Password);

                db.Useri.Add(noviKorisnik);

                db.SaveChanges();

                try
                {
                    Azure.User azureUser = new Azure.User();
                    azureUser.Ime     = Ime;
                    azureUser.Prezime = Prezime;
                    azureUser.Email   = Email;
                    azureUser.Sifra   = Validacija.createMD5(Password);

                    userTbl.InsertAsync(azureUser);

                    Validacija.message("Uspjesno ste se registrovali", "Cestitamo");
                }
                catch (Exception e)
                {
                    Validacija.message(e.Message, "Greska");
                }


                NavigationService.Navigate(typeof(View.Pocetna), noviKorisnik);
            }
        }