Exemplo n.º 1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (Session["uid"] != null)
            {
                string strcmd1 = "insert into tblLog (uId,log_type,log_time) values ( '" + Session["uid"] + "','out','" + DateTime.Now + "')";
                int    i       = dbContext.ExecNonQuery(strcmd1);
            }
        }
        catch (Exception ex)
        {
            Log.Error(ex);
        }

        Session.Clear();
        Response.Redirect("login.aspx");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            //check post back event
            if (!IsPostBack)
            {
                resetfail.Visible    = false;
                reset.Visible        = false;
                resetsuccess.Visible = false;
                string token = dataContext.Datadecrypt(Request.QueryString["tkn"].ToString().Trim());

                //check token not empty
                if (token != null)
                {
                    //get user details
                    using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString.ToString()))
                    {
                        connection.Open();
                        string        Strcity = "SELECT uId,status FROM tblForgotPassword WHERE token = " + Convert.ToInt32(token);
                        SqlCommand    cmd1    = new SqlCommand(Strcity, connection);
                        SqlDataReader dr      = cmd1.ExecuteReader();
                        if (dr.HasRows)
                        {
                            dr.Read();
                            string ststus = dr.GetValue(1).ToString();
                            //check status is active
                            if (ststus.Equals("ACTIVE"))
                            {
                                //update to status deactive
                                string str = "update tblForgotPassword set status ='DEACTIVE' where token = " + Convert.ToInt32(token);
                                int    i   = dbContext.ExecNonQuery(str);
                                if (i > 0)
                                {
                                    reset.Visible  = true;
                                    Session["uid"] = dr.GetValue(0).ToString();
                                }
                            }
                            else
                            {
                                //if password link is expired print this msg
                                resetfail.Visible    = true;
                                reset.Visible        = false;
                                resetsuccess.Visible = true;
                                resetfail.InnerText  = "Password reset link has been expired.";
                            }
                        }
                        else
                        {
                            //if token is not match print this msg
                            resetfail.Visible   = true;
                            reset.Visible       = false;
                            resetfail.InnerText = "Invalid User.";
                        }
                    }
                }
                else
                {
                    //if token is null then print this msg
                    resetfail.Visible   = true;
                    reset.Visible       = false;
                    resetfail.InnerText = "Something went worng. Please try again.";
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error(ex);
            Session.Clear();
            Response.Redirect("~/login.aspx");
        }
    }