Beispiel #1
0
        public IActionResult Login(AccountLoginVm userData)
        {
            if (ModelState.IsValid)
            {
                var getUser = pokemonContext.Users.FirstOrDefault(u => u.Username == userData.Username);

                if (getUser != null && verifyPassword(getUser, userData.Password))
                {
                    HttpContext.Session.SetString("Username", getUser.Username);
                    if (userData.Username == "admin" && verifyPassword(getUser, userData.Password))
                    {
                        return(RedirectToAction("Index", "Home", new { area = "Admin" }));
                    }

                    return(new RedirectToActionResult("Index", "Home", null));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Username or password is incorrect. Professor Oak can't remember you.");
                    return(View(userData));
                }
            }
            else
            {
                return(View(userData));
            }
        }
Beispiel #2
0
        public IActionResult Login(AccountLoginVm viewmodel)
        {
            string validUser = "******";
            string validPass = "******";

            if (ModelState.IsValid) //if form was filled in correctly
            {
                //check if provided credentials are valid (user: Joe, pas: unsafe)
                if (viewmodel.Username.Trim().Equals(validUser, StringComparison.InvariantCultureIgnoreCase)
                    &&
                    viewmodel.Password == validPass)
                {
                    //todo: add authentication code

                    return(new RedirectToActionResult("Index", "Home", null));  //redirect to homepage.
                }
                else
                {
                    ModelState.AddModelError(string.Empty,
                                             "The credentials you have provided are invalid. Please try again.");
                    return(View(viewmodel));
                }
            }
            else
            {
                return(View(viewmodel));
            }
        }
Beispiel #3
0
        private void btnLoginPrijava_Click(object sender, EventArgs e)
        {
            if (ValidateChildren())
            {
                Cursor.Current = Cursors.WaitCursor;

                AccountLoginVm account = new AccountLoginVm
                {
                    UserName = txtLoginUsername.Text,
                    Lozinka  = txtLoginPassword.Text
                };

                HttpResponseMessage response = _accountService.PostResponse(account);

                if (response.IsSuccessStatusCode)
                {
                    DialogResult = DialogResult.OK;
                    Global.prijavljeniKorisnik = response.Content.ReadAsAsync <Korisnici>().Result;
                    Close();
                }
                else
                {
                    switch (response.StatusCode)
                    {
                    case HttpStatusCode.Unauthorized:
                        MessageBox.Show(Messages.login_password_incorrect);
                        break;

                    default:
                        MessageBox.Show("Error code: " + response.StatusCode);
                        break;
                    }
                }
            }
        }
Beispiel #4
0
        public IActionResult Login()
        {
            AccountLoginVm vm = new AccountLoginVm();

            vm.Email    = "Test";
            vm.Password = "******";
            return(View(vm));
        }
        public IActionResult Login(AccountLoginVm accountLoginVm)
        {
            if (ModelState.IsValid)
            {
                //check userinfo uit database
                //indien foutief => voeg modelstate error toe
                //en stuur terug naar login

                //indien correct => stuur naar movie lijst
            }
            return(View(accountLoginVm));
        }
Beispiel #6
0
        public ActionResult Login(AccountLoginVm model)
        {
            BaseManager manager = new BaseManager();

            if (manager.UserManagerLogin(model.LoginName, model.LoginPwd))
            {
                Session["username"] = model.LoginName;
                return(Json(new { code = 200 }));
            }
            else
            {
                return(Json(new { code = 500 }));
            }
        }
        public HttpResponseMessage Login(AccountLoginVm account)
        {
            if (!ModelState.IsValid)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest));
            }

            Korisnici korisnikLogin = AccountHelper.CheckLogin(account);

            if (korisnikLogin == null)
            {
                return(Request.CreateResponse(HttpStatusCode.Unauthorized));
            }

            return(Request.CreateResponse(HttpStatusCode.Accepted, korisnikLogin));
        }
Beispiel #8
0
        public static Korisnici CheckLogin(AccountLoginVm account)
        {
            MContext ctx = new MContext();

            // Pretraga korisnika na osnovu emaila
            Korisnici korisnik = ctx.Korisnici.FirstOrDefault(u => u.Email == account.UserName);

            // Ukoliko je korisnik unio email koji ne postoji potrebno je vratiti null
            if (korisnik == null)
            {
                return(null);
            }

            // Generisanje hasha na osnovu unjete lozinke  i korisnikovog salta
            string lozinkaHash = GenerateHash(account.Lozinka, korisnik.LozinkaSalt);

            # region
            // TODO: Ovaj dio je napravljen samo za testne svrhe za predaju ispita, inace ga treba ukloniti radi sigurnosnih razloga
            if (account.UserName == "*****@*****.**" || account.UserName == "*****@*****.**")
Beispiel #9
0
        private void prijavaButton_Clicked(object sender, EventArgs e)
        {
            AccountLoginVm login = new AccountLoginVm();

            if (emailInput.Text == "" || lozinkaInput.Text == "")
            {
                DisplayAlert("Upozorenje", "Podaci nisu validni", "OK");
                return;
            }
            login.UserName = emailInput.Text;
            login.Lozinka  = lozinkaInput.Text;

            HttpResponseMessage response = loginService.PostResponse(login);

            if (response.IsSuccessStatusCode)
            {
                var jsonResult = response.Content.ReadAsStringAsync();
                Global.logedUser = JsonConvert.DeserializeObject <Korisnici>(jsonResult.Result);
                //NAGRADNA IGRA
                HttpResponseMessage responseIgra = igraService.GetActionResponse("GetKupon", Global.logedUser.Id.ToString());
                var        jsonResponse          = responseIgra.Content.ReadAsStringAsync();
                NagradnaVM Popust = JsonConvert.DeserializeObject <NagradnaVM>(jsonResponse.Result);
                if (Popust.imaPopust == "da")
                {
                    DisplayAlert("Čestitamo", "Proglašeni ste kupcem mjeseca i osvojili ste " + Popust.Popust
                                 + " popusta prilikom naredne kupovine. Vaš popust vrijedi do: " + Popust.VrijediDo + " , a šifra je: " + Popust.Sifra + " . \n  \n Vaš Exspress Salad Bar.", "OK");
                }


                Application.Current.MainPage = new Navigation.MyPage();

                //this.Navigation.PushAsync(new Navigation.MyPage());
            }
            else
            {
                DisplayAlert("Uspjeh", "Unjeli ste pogresan ime ili lozinku", "OK");
            }
        }
Beispiel #10
0
        public IActionResult Login()
        {
            var viewModel = new AccountLoginVm();

            return(View(viewModel));
        }
Beispiel #11
0
        public static Korisnici GetKorisnik(AccountLoginVm account)
        {
            MContext ctx = new MContext();

            return(ctx.Korisnici.FirstOrDefault(x => x.Email == account.UserName && x.LozinkaHash == account.Lozinka));
        }
Beispiel #12
0
 public IActionResult Login(AccountLoginVm accountLoginVm)
 {
     return(RedirectToAction("contact", "home"));
 }
        public IActionResult Login()
        {
            AccountLoginVm accountLoginVm = new AccountLoginVm();

            return(View(accountLoginVm));
        }
        private void registracijaButton_Clicked(object sender, EventArgs e)
        {
            if (imeInput.Text == "" || prezimeInput.Text == "" || telefonInput.Text == "" || emailInput.Text == "" || adresaInput.Text == "" ||
                gradInput.SelectedIndex == -1 || lozinkaInput.Text == "")
            {
                DisplayAlert("Upozorenje", "Sva polja su obavezna!", "OK");
                return;
            }
            int broj;

            if (Int32.TryParse(telefonInput.Text, out broj) == false || telefonInput.Text.Count() < 9)
            {
                DisplayAlert("Upozorenje", "Polje telefon nije validno!", "OK");
                return;
            }
            if (!HelperMethods.ValidateEmail(emailInput.Text))
            {
                DisplayAlert("Upozorenje", "Polje email nije validno!", "OK");
                return;
            }
            if (lozinkaInput.Text.Length < 6)
            {
                DisplayAlert("Upozorenje", "Lozinka mora sadržavati najmanje 6 karaktera!", "OK");
                return;
            }


            AccountRegistrationVm acc = new AccountRegistrationVm();

            acc.Ime           = imeInput.Text;
            acc.Prezime       = prezimeInput.Text;
            acc.EmailAdresa   = emailInput.Text;
            acc.Adresa        = adresaInput.Text;
            acc.Telefon       = telefonInput.Text;
            acc.Lozinka       = lozinkaInput.Text;
            acc.DatumRodjenja = datumRodjenjaInput.Date;

            if (gradInput.SelectedItem != null)
            {
                int gradId = (gradInput.SelectedItem as GetGradoviVm).Id;
                acc.GradId = gradId;

                HttpResponseMessage response = _service.PostResponse(acc);

                if (response.IsSuccessStatusCode)
                {
                    AccountLoginVm login = new AccountLoginVm();
                    login.Lozinka  = lozinkaInput.Text;
                    login.UserName = emailInput.Text;

                    HttpResponseMessage responseLogin = _service.PostCustomRouteResponse(WebApiRoutes.LOGIN_ROUTE, login);

                    if (responseLogin.IsSuccessStatusCode)
                    {
                        var jsonObject = responseLogin.Content.ReadAsStringAsync().Result;

                        Global.logedUser = JsonConvert.DeserializeObject <Korisnici>(jsonObject);

                        Navigation.PushAsync(new OdabirOmiljenih());
                    }
                    else
                    {
                        DisplayAlert("Upozorenje!", "Doslo je do greske prilikom prijave na sistem.", "OK");
                    }
                }
                else
                {
                    var json = response.Content.ReadAsStringAsync();

                    List <string> errorList = JsonConvert.DeserializeObject <List <string> >(json.Result);

                    string errors = "";
                    foreach (string error in errorList)
                    {
                        errors += error + "\n";
                    }

                    DisplayAlert("Upozorenje!", errors, "OK");
                }
            }
            else
            {
                DisplayAlert("Upozorenje!", "Potrebno je izabrati grad", "OK");
            }
        }