public async Task Auth()
        {
            try
            {
                var t = await _service.Auth(Username, Password, _selectedVrstaProizvoda.UlogaId);

                int roleId = t.Last;
                int userId = t.First;

                ULOGA u = await _service_uloga.GetById <ULOGA>(roleId);

                if (u.Naziv == "Administrator")
                {
                    Application.Current.MainPage = new AdminPage(roleId, userId);
                }
                else if (u.Naziv == "Student")
                {
                    Application.Current.MainPage = new StudPage(roleId, userId);
                }
                else if (u.Naziv == "Profesor")
                {
                    Application.Current.MainPage = new ProfPage(userId, roleId);
                }
            }
            catch (NullReferenceException e)
            {
                await Application.Current.MainPage.DisplayAlert("Greška", "Niste unijeli ispravne podatke", "OK");
            }
        }
Example #2
0
        async Task Login()
        {
            IsBusy = true;
            APIService.Username = Username;
            APIService.Password = Password;
            try
            {
                //await _service.Get<dynamic>(null);
                long t = await _serviceAuth.Auth <long>(Username, Password);

                int id = unchecked ((int)t);
                if (id != 0)
                {
                    Application.Current.MainPage = new TrenerMainPage(id);
                }
                else
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", "Neispravni podaci", "OK");
                }
            }
            catch (Exception ex)
            {
                await Application.Current.MainPage.DisplayAlert("Greška", ex.Message, "OK");
            }
        }
Example #3
0
        async Task Login()
        {
            IsBusy = true;
            APIService.Username = Username;
            APIService.Password = Password;
            if (Username == "" || Password == "")
            {
                Application.Current.MainPage.DisplayAlert("Greška", "Molimo popunite sva polja", "OK");
            }
            else
            {
                try
                {
                    //PolaznikUsernameSearchRequest request = new PolaznikUsernameSearchRequest()
                    //{
                    //    KorisnickoIme = Username
                    //};
                    //PolazniciSearchRequest request = new PolazniciSearchRequest()
                    //{
                    //    KorisnickoIme=Username
                    //};
                    //await _service.Get<dynamic>(null);
                    //await _service.Get<dynamic>();
                    long t = await _serviceAuth.Auth <long>(Username, Password);

                    int id = unchecked ((int)t);
                    // await Application.Current.MainPage.DisplayAlert("wait", id.ToString(), "ok");
                    //  int id = int.Parse(t);
                    // var entity = _service.Get<dynamic>(request);//await _service.Get<dynamic>(null);
                    /*await _service.Get<dynamic>(request)*/
                    ;

                    if (id != 0)
                    {
                        Application.Current.MainPage = new PolaznikMainPage(id);
                    }
                    else
                    {
                        t = await _serviceAuthTrener.Auth <long>(Username, Password);

                        id = unchecked ((int)t);
                        if (id != 0)
                        {
                            Application.Current.MainPage = new TrenerMainPage(id);
                        }
                        else
                        {
                            await Application.Current.MainPage.DisplayAlert("Greška", "Neispravni su podaci", "OK");
                        }
                    }
                }
                catch (Exception ex)
                {
                    await Application.Current.MainPage.DisplayAlert("Greška", ex.Message, "OK");
                }
            }
        }
Example #4
0
        async Task Login()
        {
            IsBusy = true;

            try
            {
                var _result = await _auth.Auth <Model.Korisnik>(Username, Password);

                IsBusy = false;

                if (_result != null)
                {
                    if (!_result.Token.Equals(""))
                    {
                        APIService.Session.JWT = _result.Token;

                        var jwt       = APIService.Session.JWT;
                        var handler   = new JwtSecurityTokenHandler();
                        var jsonToken = handler.ReadJwtToken(jwt);
                        if (jsonToken.ValidTo.ToLocalTime().CompareTo(DateTime.Now.ToLocalTime()) < 1)
                        {
                            APIService.Session.JWT  = "";
                            APIService.Session.Role = null;
                            return;
                        }

                        APIService.Session.BibliotekaNaziv = _result.BibliotekaNaziv;
                        APIService.Session.ImePrezime      = _result.Ime + " " + _result.Prezime;
                        APIService.Session.Slika           = _result.Slika;

                        APIService.Session.Role = new List <string>();
                        foreach (var claim in jsonToken.Claims)
                        {
                            if (claim.Type.Equals("role"))
                            {
                                APIService.Session.Role.Add(claim.Value);
                            }
                        }
                        Application.Current.MainPage = new MasterDetailPage1();
                    }
                }
                else
                {
                    IsBusy = false;
                    await Application.Current.MainPage.DisplayAlert("Greška", "Netacan username ili password", "OK");
                }
            }
            catch (Exception ex)
            {
                IsBusy = false;
            }
        }
        private async void btnPrijava_Click(object sender, EventArgs e)
        {
            if (txtUsername.Text != "" && txtPass.Text != "" && ((int)cbRole.SelectedValue != 0))
            {
                string username = txtUsername.Text;
                string pass     = txtPass.Text;
                int    ulogaId  = (int)cbRole.SelectedValue;

                try
                {
                    var id = await _service_auth.Auth(username, pass, ulogaId);

                    ULOGA u = await _service_uloga.GetById <ULOGA>(ulogaId);

                    if (id != null)
                    {
                        this.MinimizeBox = true;
                        if (u.Naziv == "Administrator")
                        {
                            frmAdmin frm = new frmAdmin((int)id[0]);
                            frm.Show();
                        }
                        else if (u.Naziv == "Student")
                        {
                            frmStud frm = new frmStud((int)id[0]);
                            frm.Show();
                        }
                        else if (u.Naziv == "Profesor")
                        {
                            frmProf frm = new frmProf((int)id[0]);
                            frm.Show();
                        }
                    }
                    //else if (id == null)
                    //{
                    //    MessageBox.Show("Unijeli ste pogrešne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //}
                }
                catch (Exception except)
                {
                    MessageBox.Show("Molimo unesite ispravne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error);
                };
            }
            else
            {
                MessageBox.Show("Molimo unesite ispravne podatke", "Upozorenje", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        async Task Login()
        {
            IsBusy = true;
            APIService.Username = Username;
            APIService.Password = Password;

            try
            {
                var user = await _korisnik.Auth <Carpool.Model.Korisnik>();

                if (user != null)
                {
                    APIService.IsVozac = user.IsVozac;
                    APIService.UserID  = user.KorisnikID;
                }
                Application.Current.MainPage = new NavigationPage(new WelcomePage());
            }
            catch (Exception)
            {
            }
        }
Example #7
0
        public async void ExecuteAsync()
        {
            Model.Korisnik result = null;
            try
            {
                result = await _auth.Auth <Model.Korisnik>(Email, Password);
            }
            catch (Exception e)
            {
                IsDialogOpen = true;
                DialogText   = e.Message;
            }
            if (result != null)
            {
                if (!result.Token.Equals(""))
                {
                    APIService.Session.JWT = result.Token;

                    var jwt       = APIService.Session.JWT;
                    var handler   = new JwtSecurityTokenHandler();
                    var jsonToken = handler.ReadJwtToken(jwt);
                    if (jsonToken.ValidTo.ToLocalTime().CompareTo(DateTime.Now.ToLocalTime()) < 1)
                    {
                        APIService.Session.JWT  = "";
                        APIService.Session.Role = null;
                        return;
                    }

                    APIService.Session.BibliotekaNaziv = result.BibliotekaNaziv;
                    APIService.Session.ImePrezime      = result.Ime + " " + result.Prezime;
                    APIService.Session.Slika           = result.Slika;

                    APIService.Session.Role = new List <string>();
                    foreach (var claim in jsonToken.Claims)
                    {
                        if (claim.Type.Equals("role"))
                        {
                            APIService.Session.Role.Add(claim.Value);
                        }
                    }
                    if (APIService.Session.Role.Contains("Korisnik"))
                    {
                        IsDialogOpen = true;
                        DialogText   = "Niste authentificirani";
                        return;
                    }

                    if (RememberMe)
                    {
                        Properties.Settings.Default.Element2   = EncryptionHelper.Encrypt(Password);
                        Properties.Settings.Default.RememberMe = true;
                        Properties.Settings.Default.Element1   = EncryptionHelper.Encrypt(Email);
                        Properties.Settings.Default.Save();
                    }

                    var mv = new MainWindow();
                    mv.Show();

                    Application.Current.MainWindow.Close();
                }
            }
        }