Esempio n. 1
0
    protected void btnSave_Click1(object sender, EventArgs e)
    {
        Users objUser = new Users();
        objUser.Data.Email = txtEmail.Text.Trim();
        objUser.Data.Username = txtUsersName.Text.Trim();
        objUser.Data.RoleID = ConvertData.ConvertToInt(ddlRole.SelectedValue);
        if (chkActive.Checked)
            objUser.Data.Status = EnumeType.ACTIVE;
        else
            objUser.Data.Status = EnumeType.INACTIVE;

        ClsEncrypt objEnCrypt = new ClsEncrypt();
        objUser.Data.Password = objEnCrypt.Encrypt(txtPasswords.Text);

        int nResult = 0;
        string sLink = "";
        string sAction = Request.QueryString[Constants.ACTION];
        switch (sAction)
        {
            case Constants.ACTION_ADD:

                DataTable dtbUser = new DataTable();
                string strUserEmail = txtEmail.Text;
                dtbUser = objUser.GetUserByEmail(strUserEmail, 1);
                if (dtbUser.Rows.Count > 0)
                {
                    MessageBoxss.Show(MessagesAlert.EMAIL_EXISTED);

                }
                else {

                    nResult = objUser.Insert();
                    if (nResult > 0)
                    {

                        sLink = Constants.ROOT + Pages.BackEnds.ADMIN + "?" + Constants.PAGE + "=" + Pages.BackEnds.STR_USER + "&" + Constants.MESS_ID + "=" + Constants.MESSAGE_INSERT;
                        Response.Redirect(sLink);
                    }
                    else
                        MessageBoxss.Show(MessagesAlert.INSERT_UNSUCCESSFUL);
                }

                break;
            case Constants.ACTION_EDIT:
                int nID = ConvertData.ConvertToInt(Request.QueryString[Constants.ACTION_ID]);
                nResult = objUser.Update(nID);
                if (nResult > 0)
                {
                    MessageBoxss.Show(MessagesAlert.UPDATE_SUCCESSFUL);

                }
                else
                    MessageBoxss.Show(MessagesAlert.UPDATE_UNSUCCESSFUL);
                break;
        }
    }
Esempio n. 2
0
    private bool isUser()
    {
        bool isUser = false;
        string sEmail = username_id.Text.Trim();
        string sUsername = "";
        sEmail = sEmail.ToLower();
        string sPassword = password.Text.Trim();
        Users objUser = new Users();
        DataTable dtbUser = new DataTable();

        try
        {
            dtbUser = objUser.GetUserByEmail(sEmail, EnumeType.ACTIVE);
            string sCurrentEmail = ConvertData.ConvertToString(dtbUser.Rows[0]["Email"]);
            string sCurrentPassword = ConvertData.ConvertToString(dtbUser.Rows[0]["Password"]);
            sUsername = ConvertData.ConvertToString(dtbUser.Rows[0]["Username"]);

            ClsEncrypt obj = new ClsEncrypt();
            string sDeCodePass = obj.Decrypt(sCurrentPassword);
            if (sEmail == sCurrentEmail && sPassword == sDeCodePass)
            {
                Session.Timeout = 95000;
                Session[Constants.SESSION_USERNAME] = ConvertData.ConvertToString(sUsername);
                Session[Constants.SESSION_USEREMAIL] = ConvertData.ConvertToString(sEmail);

                isUser = true;
            }
            else
                isUser = false;
        }
        catch (Exception)
        {
            isUser = false;
        }
        return isUser;
    }