示例#1
0
    protected void ButtonLogin_Click(object sender, EventArgs e)
    {
        Pontaje_firma_topografieEntities db = new Pontaje_firma_topografieEntities();
        string username = TextBoxUsername.Text;
        string password = GetHashedText(TextBoxPassword.Text);
        var    u        = (from user in db.Users where user.username == username && user.password == password select user).FirstOrDefault();

        if (u != null)
        {
            Session["username"] = TextBoxUsername.Text;
            int id_user = (from user in db.Users where user.username == username select user.id).FirstOrDefault();
            Session["id_user"] = id_user;
            int id_role = (from user in db.Users where user.username == username select user.id_role).FirstOrDefault();
            if (id_role == 1)
            {
                Response.Redirect("AdminMain.aspx");
            }
            else if (id_role == 2)
            {
                Response.Redirect("Main.aspx");
            }
            else if (id_role == 3)
            {
                Response.Redirect("DriverMain.aspx");
            }
            Session.RemoveAll();
        }
        else
        {
            LabelWrong.Visible = true;
        }
    }
示例#2
0
    protected void ButtonRegister_Click(object sender, EventArgs e)
    {
        LabelMismatch.Visible       = false;
        LabelUsernameExists.Visible = false;
        Pontaje_firma_topografieEntities pe = new Pontaje_firma_topografieEntities();
        User user = new User();

        user.first_name = TextBoxFirstName.Text;
        user.last_name  = TextBoxLastName.Text;
        user.email      = TextBoxEmail.Text;
        user.username   = TextBoxUsername.Text;
        user.password   = GetHashedText(TextBoxPassword.Text);
        var check_username = (from u in pe.Users where u.username == TextBoxUsername.Text select u).Count();

        if (check_username == 1)
        {
            LabelUsernameExists.Visible = true;
        }
        else
        {
            if (GetHashedText(TextBoxPassword.Text) != GetHashedText(TextBoxConfirmPassword.Text))
            {
                LabelMismatch.Visible = true;
            }
            else
            {
                user.id_role = Int32.Parse(DropDownList1.SelectedItem.Value);
                pe.Users.Add(user);
                pe.SaveChanges();
                Response.Redirect("AdminMain.aspx");
            }
        }
    }