protected void btnRegistracija_Click(object sender, EventArgs e)
        {
            Kupci k = DAKupci.provjeriEmail(tbEmail.Text);

            if (k == null)
            {
                Kupci kup = new Kupci();
                kup.Ime               = tbIme.Text;
                kup.Prezime           = tbPrezime.Text;
                kup.DatumRegistracije = DateTime.Now;
                kup.Email             = tbEmail.Text;
                string salt = UIHelper.GenerateSalt();
                kup.LozinkaSalt = salt;
                kup.LozinkaHash = UIHelper.GenerateHash(tbPassword.Text, salt);
                kup.Status      = true;

                DAKupci.Insert(kup);

                Response.Redirect("/KorisniciSistema/Prijava.aspx");

                ClearForm();
            }
            else
            {
                string display = "Email je zauzet!";
                ClientScript.RegisterStartupScript(this.GetType(), "Upozorenje", "alert('" + display + "');", true);
            }
        }
        protected void btnPrijava_Click(object sender, EventArgs e)
        {
            if (tbKorisnicko.Text != "" && tbLozinka.Text != "")
            {
                Kupci k = DAKupci.logiranje(tbKorisnicko.Text, tbLozinka.Text);

                if (k != null)
                {
                    Session["kupac"] = k;
                    FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(k.KupacID.ToString(), false, 30);
                    string     encryptTicket         = FormsAuthentication.Encrypt(ticket);
                    HttpCookie loginCookie           = new HttpCookie(FormsAuthentication.FormsCookieName, encryptTicket);
                    Response.Cookies.Add(loginCookie);

                    Response.Redirect(FormsAuthentication.GetRedirectUrl(k.KupacID.ToString(), false));

                    logiran = true;
                }
                else
                {
                    logiran           = false;
                    tbLozinka.Text    = "";
                    tbKorisnicko.Text = "";
                    CustomValidator err = new CustomValidator();
                    err.IsValid      = false;
                    err.ErrorMessage = "Kombinacija korisničkog imena i lozinke je netačna!";
                    Page.Validators.Add(err);
                    ValidationSummary1.ShowMessageBox = true;
                }
            }
        }
Exemplo n.º 3
0
        private void BindForm()
        {
            Kupci k = DAKupci.getByID(logirani);

            tbEmail.Text   = k.Email;
            tbIme.Text     = k.Ime;
            tbPrezime.Text = k.Prezime;
        }
Exemplo n.º 4
0
        protected void btnSacuvaj_Click(object sender, EventArgs e)
        {
            Kupci k = DAKupci.provjeriEmail(tbEmail.Text);

            if (k == null)
            {
                Kupci kup = new Kupci();
                kup.KupacID = Convert.ToInt32(User.Identity.Name);
                kup.Email   = tbEmail.Text;
                string salt = UIHelper.GenerateSalt();
                kup.LozinkaSalt = salt;
                kup.LozinkaHash = UIHelper.GenerateHash(tbPassword.Text, salt);
                DAKupci.update(kup);

                BindForm();
            }
        }