protected void Page_Load(object sender, EventArgs e) { if (Session["uname"] != null && Session["uid"] != null) { string connstring = ConfigurationManager.ConnectionStrings["ConnString"].ConnectionString; DAL d = new DAL(connstring); d.AddParam("UserID", Session["uid"]); DataSet ds = d.ExecuteProcedure("spGetUser"); if (ds.Tables[0].Rows[0]["Username"].ToString()=="admin") { string s = this.ContentPlaceHolder1.Page.GetType().FullName; if (s!="ASP.admin_aspx") { lnkAdmin.Visible = true; } } else { lnkAdmin.Visible = false; } pnlLoggedIn.Visible = true; pnlLoggedOut.Visible = false; lblUsername.Text = Session["uname"].ToString(); } else { pnlLoggedOut.Visible = true; pnlLoggedIn.Visible = false; } }
private void BindData() { DAL d = new DAL(ConfigurationManager.ConnectionStrings["connString"].ConnectionString); d.AddParam("UserID", null); gvUsers.DataSource = d.ExecuteProcedure("spGetUser"); gvUsers.DataBind(); }
public string ForgotPassword(string email) { Context.Response.Clear(); Context.Response.ContentType = "text/plain"; string newPassword = GenerateRandomString(25); DAL d = new DAL(ConfigurationManager.ConnectionStrings["connString"].ConnectionString); d.AddParam("Email", email); d.AddParam("NewPassword", newPassword); DataSet ds = d.ExecuteProcedure("spForgotPassword"); string body = "New password: <b>" + newPassword + "</b>"; if (Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]) > 0) { SendEmail(email, body); return "Success"; } else { return "Failure"; } }
public string CheckUser(string user) { Context.Response.Clear(); Context.Response.ContentType = "text/plain"; DAL d = new DAL(connstring); d.AddParam("Username", user); DataSet ds = d.ExecuteProcedure("spCheckUserName"); if (ds.Tables[0].Rows.Count == 0) { return "UserName OK!, proceed"; } else { return "UserName taken, please choose another one"; } }
public string UpdateParagraphText(string text,int id) { try { Context.Response.Clear(); Context.Response.ContentType = "text/plain"; DAL d = new DAL(connstring); d.AddParam("id", id+1); d.AddParam("ParagraphText", text); DataSet ds = d.ExecuteProcedure("spUpdateParagraphText"); return "Paragraph Updated"; } catch (Exception e) { return "error: "+e.Message; } }
public string Login(string connString, string user, string password) { DAL dal = new DAL(connString); dal.AddParam("@UserName", user); dal.AddParam("@Password", password); DataSet ds = dal.ExecuteProcedure("spLogin"); if (ds.Tables[0].Rows.Count> 0) { this.userid = Convert.ToInt32(ds.Tables[0].Rows[0]["UserID"]); this.firstName=ds.Tables[0].Rows[0]["FirstName"].ToString(); this.lastName=ds.Tables[0].Rows[0]["LastName"].ToString(); this.city=ds.Tables[0].Rows[0]["City"].ToString(); this.address=ds.Tables[0].Rows[0]["Address"].ToString(); this.email=ds.Tables[0].Rows[0]["Email"].ToString(); this.userName=ds.Tables[0].Rows[0]["UserName"].ToString(); this.password=ds.Tables[0].Rows[0]["Password"].ToString(); this.isAdmin=Convert.ToInt32(ds.Tables[0].Rows[0]["IsAdmin"]); return "success"; } else { return "Login Failed"; } }
public DataSet SaveToDB(string connString) { DAL dal = new DAL(connString); dal.AddParam("@FirstName", firstName); dal.AddParam("@LastName", lastName); dal.AddParam("@Address", address); dal.AddParam("@City", city); dal.AddParam("@Email", email); dal.AddParam("@UserName", userName); dal.AddParam("@Password", password); DataSet ds = dal.ExecuteProcedure("spRegister"); if (ds.Tables[0].Rows[0]["NewUserID"].ToString() != "") { this.userid = Convert.ToInt32(ds.Tables[0].Rows[0]["NewUserID"]); } return ds; }