public string DeleteUserTasks(string json) { log4net.ILog log = log4net.LogManager.GetLogger(typeof(Soap)); new ConfigHelper().Load(); try { if (string.IsNullOrEmpty(json)) { return(string.Empty); } AdminObject deleteObject = JsonHelper.OnlyJsonToObject <AdminObject>(json); if (deleteObject == null) { return(string.Empty); } string userId = deleteObject.UserId; string password = deleteObject.Password; if (ServicesConstants.DELETE_PASSWORD.Equals(password) == false || string.IsNullOrEmpty(userId)) { return(string.Empty); } GenericDbHelper.RunDirectSql(string.Format("DELETE FROM TASK WHERE USER_ID = '{0}'", userId)); return("OK"); } catch (Exception e) { log.Error(e); return(e.ToString()); } }
protected void Page_Load(object sender, EventArgs e) { Page.MaintainScrollPositionOnPostBack = true; //Check if there is authenticated Admin logged in if (HttpContext.Current.User.Identity.IsAuthenticated) { AdminObject admin = (AdminObject)Session["Admin"]; if (admin != null) { adminName.Text = admin.Name; } else { //Creating Identity for Admin to retrieve ticket FormsIdentity adminIdentity = HttpContext.Current.User.Identity as FormsIdentity; FormsAuthenticationTicket ticket = adminIdentity.Ticket; //If the ticket not expired, creating new session if (!ticket.Expired) { //Building read query string query = "select * from tblAdmins where Email='" + ticket.Name + "'"; //Getting reader result var reader = dbCommander.ReadRecord(query); if (reader != null) { AdminObject requestedAdmin = new AdminObject(); while (reader.Read()) { requestedAdmin.AdminID = (Guid)reader["AdminID"]; requestedAdmin.Name = (String)reader["Name"]; requestedAdmin.Email = (String)reader["Email"]; } //Closing connection dbCommander.CloseConnection(); Session["Admin"] = requestedAdmin; adminName.Text = requestedAdmin.Name; } else { dbCommander.CloseConnection(); } } } } }
/* * @Method: AddAdminBtn_Click * @Params: object sender, EventArgs e * @Return: void * @Description: This method will be activated on the click of submit admin button. * A new ID will be assigned to the new admin, and password will be hashed, and * saved in the database using SQL Data Access Layer */ protected void AddAdminBtn_Click(object sender, EventArgs e) { AdminObject admin = new AdminObject(); //Creating new unique ID to the admin object admin.AdminID = Guid.NewGuid(); //Getting new hashed password PasswordHasher hasher = new PasswordHasher(); string hashedPassword = hasher.GetHashedPassword(AdminPasswordInput.Text, AdminEmailInput.Text); //Constructing the insert query string query = "insert into tblAdmins values('" + admin.AdminID + "','" + AdminNameInput.Text + "','" + AdminEmailInput.Text + "','" + hashedPassword + "')"; string result = dbCommander.InsertRecord(query); if (result == "1") { //Success message Response.Write("<script>alert('Admin inserted');</script>"); //Clearing all the input fields AdminNameInput.Text = string.Empty; AdminEmailInput.Text = string.Empty; AdminPasswordInput.Text = string.Empty; } else { //If the user is not inserted, show that there was an error with the database Response.Write ("<script>alert('Database error, please check your provided data to be correct');</script>"); } //Closing connection to database dbCommander.CloseConnection(); //Refresh the GridView AdminGridView.DataBind(); }
protected void Page_Load(object sender, EventArgs e) { //Check if there is authenticated Admin logged in if (HttpContext.Current.User.Identity.IsAuthenticated) { //Creating Identity for Admin to retrieve ticket FormsIdentity adminIdentity = HttpContext.Current.User.Identity as FormsIdentity; FormsAuthenticationTicket ticket = adminIdentity.Ticket; //If the ticket not expired, creating new session if (!ticket.Expired) { //Building read query string query = "select * from tblAdmins where Email='" + ticket.Name + "'"; //Getting reader result var reader = dbCommander.ReadRecord(query); if (reader != null) { AdminObject requestedAdmin = new AdminObject(); while (reader.Read()) { requestedAdmin.AdminID = (Guid)reader["AdminID"]; requestedAdmin.Name = (String)reader["Name"]; requestedAdmin.Email = (String)reader["Email"]; } Session["Admin"] = requestedAdmin; //Closing connection dbCommander.CloseConnection(); //Redirecting to AdminManagement Page Response.Redirect("/Admin/AdminManagement.aspx"); } } } }
private List <Task> GetAllTaskFromServer() { AdminObject deleteObject = new AdminObject(); deleteObject.UserId = m_userId; deleteObject.Password = ServicesConstants.DELETE_PASSWORD; string json = JsonHelper.ConvertToJson <AdminObject>(deleteObject); string requestString = "{\"json\" : \" "; requestString += Regex.Replace(json, "\"", "\\\""); requestString += "\"}"; HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(string.Format("http://{0}/Minder.WebServices/Default.asmx/GetUserTasks", SyncController.SERVER_IP)); request.ContentType = "application/json; charset=utf-8"; request.Accept = "application/json, text/javascript, */*"; request.Method = "POST"; request.Timeout = 1000 * 10; //10 Seconds using (StreamWriter writer = new StreamWriter(request.GetRequestStream())) { writer.Write(requestString); } WebResponse response = request.GetResponse(); Stream stream = response.GetResponseStream(); string resultJson = ""; using (StreamReader reader = new StreamReader(stream)) { while (!reader.EndOfStream) { resultJson += reader.ReadLine(); } } Minder.Objects.SyncObject result = JsonHelper.JsonToObject <Minder.Objects.SyncObject>(resultJson); return(result.Tasks); }
public string GetUserTasks(string json) { log4net.ILog log = log4net.LogManager.GetLogger(typeof(Soap)); new ConfigHelper().Load(); try { if (string.IsNullOrEmpty(json)) { return(string.Empty); } AdminObject adminObject = JsonHelper.OnlyJsonToObject <AdminObject>(json); if (adminObject == null) { return(string.Empty); } string userId = adminObject.UserId; string password = adminObject.Password; if (ServicesConstants.DELETE_PASSWORD.Equals(password) == false || string.IsNullOrEmpty(userId)) { return(string.Empty); } List <TaskSync> tasks = GenericDbHelper.Get <TaskSync>(string.Format("USER_ID = '{0}'", userId)); SyncObject result = new SyncObject(); result.Tasks = tasks; return(JsonHelper.ConvertToJson <SyncObject>(result)); } catch (Exception e) { log.Error(e); return(e.ToString()); } }
protected void loginBtn_Click(object sender, EventArgs e) { try { //Hashing the given password by admin for comparison PasswordHasher hasher = new PasswordHasher(); string hashedPassword = hasher.GetHashedPassword(passwordInput.Text, emailInput.Text); //Building read query string query = "select * from tblAdmins where Email='" + emailInput.Text + "' and PasswordHash='" + hashedPassword + "'"; //Getting reader result var reader = dbCommander.ReadRecord(query); //Check if the reader has returned rows or not if (reader.HasRows) { AdminObject requestedAdmin = new AdminObject(); while (reader.Read()) { requestedAdmin.Name = (String)reader["Name"]; requestedAdmin.Email = (String)reader["Email"]; requestedAdmin.AdminID = (Guid)reader["AdminID"]; } //Admin info is added to the session Session["Admin"] = requestedAdmin; //Create Authentication ticket FormsAuthenticationTicket ticket; string cookieInfo; HttpCookie adminCookie; //Stay logged in ticket if (stayLogged.Checked) { ticket = new FormsAuthenticationTicket(requestedAdmin.Email, true, 60); } //Not to stay logged in ticket else { ticket = new FormsAuthenticationTicket(requestedAdmin.Email, false, 1); } //Adding the authentication ticket to a cookie cookieInfo = FormsAuthentication.Encrypt(ticket); adminCookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieInfo); adminCookie.Expires = ticket.Expiration; adminCookie.Path = FormsAuthentication.FormsCookiePath; Response.Cookies.Add(adminCookie); //Closing database connection dbCommander.CloseConnection(); //Redirecting to AdminManagement page Response.Redirect("/Admin/AdminManagement.aspx"); } else { throw new NullReferenceException(); } } catch (NullReferenceException) { //If the the credentials are not correct, show error Response.Write ("<script>alert('Wrong credentials, please check your provided data to be correct');</script>"); //Closing connection after exception dbCommander.CloseConnection(); } }