protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["ID"] != null)
        {
            if (!Account.ValidEmail(Account.ID2Email(Convert.ToUInt32(Request.QueryString["ID"].ToString()))))
                Response.Redirect("~Admin/Clients");

            if (Session["User"] == null)
                Response.Redirect("~/Account/Login?ReturnUrl=Admin/Clients");

            WebsiteUser Op = (WebsiteUser)Session["User"];

            if (Op.Level != 3)
                Response.Redirect("~/Default");

            if (!IsPostBack)
            {
                WebsiteUser Client = new WebsiteUser(Account.ID2Email(Convert.ToUInt32(Request.QueryString["ID"].ToString())), 1);

                Nome.Text = Client.Username;
                Contacto.Text = Convert.ToString(Client.Contact);
                Email.Text = Client.Email;
                Morada.Text = Client.Address;
                BI.Text = Convert.ToString(Client.CC);
                Contribuinte.Text = Convert.ToString(Client.FiscalNumber);
            }
        }
        else
            Response.Redirect("~/Admin/Clients");
    }
    protected void LogIn(object sender, EventArgs e)
    {
        if (Page.IsValid)
            {
                if(Account.ValidEmail(Email.Text))
                {
                    switch(Account.Login(Email.Text, Password.Text, Response))
                    {
                        case 0:
                            FailureText.Text = "Dados incorrectos ou conta recentemente eliminada.";
                            ErrorMessage.Visible = true;
                            break;
                        case 1:
                            Session["User"] = new WebsiteUser(Email.Text, 1);

                            if (Request.QueryString["ReturnUrl"] != null)
                            {
                                Response.Redirect("~/" + Request.QueryString["ReturnUrl"].ToString());
                            }
                            else
                                Response.Redirect("~/Account/Manage");
                            break;
                        case 2:
                            Session["User"] = new WebsiteUser(Email.Text, 2);

                            if (Request.QueryString["ReturnUrl"] != null)
                            {
                                Response.Redirect("~/" + Request.QueryString["ReturnUrl"].ToString());
                            }
                            else
                                Response.Redirect("~/Account/Manage");
                            break;
                        case 3:
                            Session["User"] = new WebsiteUser(Email.Text, 3);

                            if (Request.QueryString["ReturnUrl"] != null)
                            {
                                Response.Redirect("~/" + Request.QueryString["ReturnUrl"].ToString());
                            }
                            else
                                Response.Redirect("~/Account/Manage");
                            break;
                    }
                }
                else
                {
                    FailureText.Text = "Conta inexistente.";
                    ErrorMessage.Visible = true;
                }
            }
    }
    protected void SaveData_Click(object sender, EventArgs e)
    {
        WebsiteUser Client = new WebsiteUser(Account.ID2Email(Convert.ToUInt32(Request.QueryString["ID"].ToString())), 1);

        Client.Contact = Convert.ToDouble(Contacto.Text);
        Client.Email = Email.Text;
        Client.Address = Morada.Text;
        Client.CC = Convert.ToUInt32(BI.Text);
        Client.FiscalNumber = Convert.ToUInt32(Contribuinte.Text);

        if (Client.SaveChangesToDatabase())
        {
            FailureText.Text = "Dados alterados com sucesso.";
            ErrorMessage.Visible = true;
        }
        else
        {
            FailureText.Text = "Erro ao alterar dados.";
            ErrorMessage.Visible = true;
        }
    }
    protected void SaveData_Click(object sender, EventArgs e)
    {
        WebsiteUser Op = (WebsiteUser)Session["User"];

        Op.Contact = Convert.ToDouble(Contacto.Text);
        Op.Email = Email.Text;
        Op.Address = Morada.Text;
        Op.CC = Convert.ToUInt32(BI.Text);
        Op.FiscalNumber = Convert.ToUInt32(Contribuinte.Text);

        if(Op.SaveChangesToDatabase())
        {
            FailureText.Text = "Dados alterados com sucesso.";
            ErrorMessage.Visible = true;
            Session["User"] = new WebsiteUser(Op.Email, 1);
        }
        else
        {
            FailureText.Text = "Erro ao alterar dados.";
            ErrorMessage.Visible = true;
        }
    }
    protected void ChangePassword(object sender, EventArgs e)
    {
        WebsiteUser Op = (WebsiteUser)Session["User"];

        if (IsValid)
        {
            if (SEM.Encrypt(CurrentPassword.Text, Account.Email2Hash(Op.Email)) == Account.Email2EncryptedPassword(Op.Email))
            {
                if (SEM.Encrypt(CurrentPassword.Text, Account.Email2Hash(Op.Email)) != SEM.Encrypt(NewPassword.Text, Account.Email2Hash(Op.Email)))
                {
                    Op.EncryptedPassword = SEM.Encrypt(NewPassword.Text, Account.Email2Hash(Op.Email));
                    if(Op.SaveChangesToDatabase())
                    {
                        FailureText.Text = "Password alterada com sucesso. Por favor volte a fazer login.";
                        ErrorMessage.Visible = true;
                        Session["User"] = new WebsiteUser(Op.Email, 1);
                        Response.AddHeader("REFRESH", "5;URL=Logout");
                    }
                    else
                    {
                        FailureText.Text = "Erro desconhecido.";
                        ErrorMessage.Visible = true;
                    }
                }
                else
                {
                    FailureText.Text = "Password actual nao pode ser igual à nova.";
                    ErrorMessage.Visible = true;
                }
            }
            else
            {
                FailureText.Text = "Password actual incorrecta.";
                ErrorMessage.Visible = true;
            }
        }
    }
Example #6
0
    public static void LoadPayments(WebsiteUser Obj, HttpResponse Response)
    {
        String query = String.Format("SELECT * FROM dbo.PAGAMENTO WHERE IDCLIENTE='{0}'", Obj.ClientID);

        DataTable temp;
        temp = db.GetDataTable(query);

        foreach(DataRow r in temp.Rows)
        {
            Response.Write("<div class='col-md-4'>");
            Response.Write("<h4><u>Data: </u> " + r["DATA_LIMITE"].ToString().Remove(11) + "</h4>");
            Response.Write("<p><a class='btn btn-default' href='\\Account\\Payments\\Payment?PaymentID=" + r["IDPAGAMENTO"].ToString() + "'>Detalhes &raquo;</a></p>");
            Response.Write("</div>");
        }
    }
Example #7
0
    public static Boolean isValidOwner(WebsiteUser obj, UInt32 AnimalID)
    {
        db = new SQLDatabaseManager();

        String query = "SELECT * FROM dbo.ANIMAL WHERE IDCLIENTE='" + obj.ClientID + "' AND IDANIMAL='" + AnimalID + "'";

        DataTable temp;
        temp = db.GetDataTable(query);

        if (temp.Rows.Count > 0)
            return true;
        return false;
    }