/// <summary>获取用户列表 </summary> /// <param name="nameValues">列表参数</param> /// <param name="page">分页信息</param> /// <returns>用户实体集合</returns> public List <FlightAlarmAddressee> GetList(NameValueCollection nameValues, DataPage page) { List <FlightAlarmAddressee> addresseeList = new List <FlightAlarmAddressee>(); addresseeList = UserPersistence.GetList(nameValues, page); return(addresseeList); }
public static bool AuthenticateUser(Credential credential, HttpSessionStateBase httpSessionStateBase) { httpSessionStateBase["LoggedIn"] = false;//comment2 httpSessionStateBase["IsAdmin"] = false; httpSessionStateBase["IsProvider"] = false; User user = UserPersistence.GetUser(credential.UserId); if (user == null) { System.Diagnostics.Debug.WriteLine("Nulllll user "); return(false); } String pHash = EncryptionManager.EncodePassword(credential.Password, user.Salt); System.Diagnostics.Debug.WriteLine("realOne: " + EncryptionManager.EncodePassword("sa", user.Salt)); System.Diagnostics.Debug.WriteLine("phash: " + pHash); System.Diagnostics.Debug.WriteLine("user passsHash: " + user.PasswordHash); if (pHash != user.PasswordHash) { return(false); } else { httpSessionStateBase["LoggedIn"] = true; httpSessionStateBase["IsAdmin"] = user.IsAdmin; httpSessionStateBase["IsProvider"] = user.IsProvider; return(true); } }
/// <summary> /// /// </summary> /// <param name="users"></param> /// <returns></returns> public MethodResponse <Guid[]> CreateUsers(User[] users) { List <Guid> guids = new List <Guid>(); MethodResponse <Guid[]> returnCodes = new MethodResponse <Guid[]>(); foreach (var user in users) { try { using (TransactionScope transactionScope = new TransactionScope()) { guids.Add(UserPersistence.AddUser(user, null)); transactionScope.Complete(); } } catch (Exception exception) { EventLog.Error("{0}, {1}", exception.Message, exception.StackTrace); returnCodes.AddError(exception, 0); guids.Add(Guid.Empty); } } returnCodes.Result = guids.ToArray(); return(returnCodes); }
// GET: api/User/5 public User Get(long id) { UserPersistence up = new UserPersistence(); User user = up.getUser(id); return(user); }
/// <summary> /// Modify a specific user by username /// </summary> /// <param name="Username"></param> /// <param name="value"></param> /// <returns></returns> // PUT: api/User/eng_same7 public HttpResponseMessage Put(long UserID, [FromBody] User value) { bool recordExisted = false; User UserData = new User() { UserID = UserID, Username = value.Username, FirstName = value.FirstName, LastName = value.LastName, Email = value.Email, Password = value.Password }; recordExisted = UserPersistence.UpdateUser(UserData); HttpResponseMessage response; if (recordExisted) { // !Comment: return 402 -> record found with no content. response = Request.CreateResponse(HttpStatusCode.NoContent); } else { // !Comment: return 404 -> record not found. response = Request.CreateResponse(HttpStatusCode.NotFound); } return(response); }
/// <summary> /// Get a specific user by his\her username /// </summary> /// <param name="Username">Username to check for</param> /// <returns></returns> // GET: api/User/?Username= public User Get(string Username) { User udtResult = new User(); User ResultUser = UserPersistence.GetUser(Username); if (Request.Headers.Contains("Password")) { string Password = Request.Headers.GetValues("Password").First(); } if (ResultUser != null) { udtResult.UserID = ResultUser.UserID; udtResult.Username = ResultUser.Username; udtResult.FirstName = ResultUser.FirstName; udtResult.LastName = ResultUser.LastName; udtResult.Email = ResultUser.Email; udtResult.Password = ResultUser.Password; } else { /*To be Changed*/ throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(ResultUser); }
public ActionResult AddComment(Comment comment, String sTitle) { System.Diagnostics.Debug.WriteLine("sesss" + Session["LoggedIn"]); if (Session["LoggedIn"] == null || Session["LoggedIn"].Equals(false) || Session["LoggedIn"].ToString().Length == 0) { TempData["commentAdded"] = "Please Log in."; return(View(comment)); } comment.Writer = UserPersistence.GetUser(Session["userId"].ToString()); comment.CommentId = CommentPersistence.getMaxId() + 1; System.Diagnostics.Debug.WriteLine("***" + sTitle); comment.Service = ServicePersistence.GetService(sTitle); bool?acceptible = false; acceptible = CommentManager.AddNewComment(comment); if ((acceptible != null)) { if (acceptible == true) { TempData["commentAdded"] = "Comment is added successfully."; return(RedirectToAction("Index", "Home")); } else { TempData["commenteAdded"] = "Comment could not be added."; return(View(comment)); } } else { TempData["commentAdded"] = "Comment could not be added."; return(View(comment)); } }
/* * Transaction: Delete an user from the database * Returns true if the user exists in the database and * it was successfully deleted. */ public static bool DeleteUser(User delUser) { if (UserPersistence.getUserDB(delUser) == null) { return(false); } return(UserPersistence.DeleteUser(delUser)); }
/// <summary> /// Adds the new user into the database. /// </summary> /// <param name="cr">Credentials for the new user.</param> /// <param name="baseState"></param> /// <returns>Boolean value whether the transaction is happened or not.</returns> public static bool SignUpUser(Credential cr, HttpSessionStateBase baseState) { baseState["LoggedIn"] = false; baseState["IsAdmin"] = false; return(UserPersistence.AddUser(cr)); }
/* * Transaction: Update an user in the database * Returns true if the user exists in the database and * it was successfully changed. */ public static bool ChangeUser(User changeUser) { if (UserPersistence.getUserDB(changeUser) == null) { return(false); } return(UserPersistence.UpdateUserName(changeUser)); }
public ActionResult ProfilePage() { User user = UserPersistence.GetUser(Session["UserId"].ToString()); if (user != null && user.IsAdmin) { return(RedirectToAction("AdminPage", "Admin")); } return(View(user)); }
public ArrayList GetSearch(string text) { UserPersistence pp = new UserPersistence(); var p = pp.searchUser(text); if (p == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(p); }
// GET: api/Person/5 public User Get(String id) { UserPersistence pp = new UserPersistence(); User p = pp.getUser(id); if (p == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(p); }
public ActionResult ChangeUser(int id) { User user = UserPersistence.getUserID(id); if (user == null) { return(HttpNotFound()); } Session["user"] = user; return(View("ChangeUser", user)); }
/// <summary>根据输入信息异步获取数据姓名+工号</summary> /// <param name="name">前台输入信息</param> /// <returns>搜索结果List</returns> public List <FlightAlarmAddressee> GetAjaxList(string name = null) { List <FlightAlarmAddressee> result = null; var allList = UserPersistence.GetAllList(); const int SelectCount = 30; result = !string.IsNullOrEmpty(name) ? allList.Where(t => t.FAAName.Contains(name.Trim())).Take(SelectCount).ToList() : allList.Take(SelectCount).ToList(); return(result); }
/// <summary> /// Create/Save a new user /// </summary> /// <param name="value"></param> /// <returns></returns> // POST: api/User public HttpResponseMessage Post([FromBody] User Value) { long id; id = UserPersistence.SaveUser(Value); HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); // !Comment: This is used to set the location of the posted id in the header after the post is done. response.Headers.Location = new Uri(Request.RequestUri, string.Format("user/{0}", id)); return(response); }
public Persistence(Uri endpointUri, string primaryKey, string databaseId) { _databaseId = databaseId; _endpointUri = endpointUri; _primaryKey = primaryKey; _client = new DocumentClient(endpointUri, primaryKey); _client.OpenAsync(); Samples = new SamplePersistence(_client, _databaseId); Users = new UserPersistence(_client, _databaseId); }
// POST: api/User public HttpResponseMessage Post([FromBody] User value) { UserPersistence up = new UserPersistence(); long id; id = up.saveUser(value); value.ID = id; HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Created); response.Headers.Location = new Uri(Request.RequestUri, String.Format("user/{0}", id)); return(response); }
/* * Transaction: Delete a book from the database * Returns true iff the book exists in the database and * it was successfully deleted. */ public static bool DeleteUser(User delUser) { // Verify that the user already exists User oldUser = UserPersistence.GetUser(delUser.UserId); // oldUser shouldnot be null, if this is a old user if (oldUser == null) { return(false); } return(UserPersistence.DeleteUser(delUser)); }
public ActionResult UserName(string name) { name = (string)Session["UserId"]; User user = UserPersistence.getUserName(name); if (user == null) { return(HttpNotFound()); } Session["user"] = user; return(View("UserName", user)); }
/* * Transaction: Update a user in the database * Returns true iff the user exists in the database and * it was successfully changed. */ public static bool ChangeUser(User upUser) { // Verify that the user already exists User oldUser = UserPersistence.GetUser(upUser.UserId); // oldUser should not be null, if this is a existing user if (oldUser == null) { return(false); } return(UserPersistence.UpdateUser(upUser)); }
public ActionResult Login(Credential credential) { if (credential == null) { return(View(new Credential())); } if (credential.Password == null || credential.UserId == null) { string err = "Both User ID and Password are required. Please try again."; TempData["message"] = err; return(View(credential)); } if (credential.Password.Length == 0 || credential.UserId.Length == 0) { string err = "Both User ID and Password are required. Please try again."; TempData["message"] = err; return(View(credential)); } User user = UserPersistence.GetUser(credential.UserId); // Get the user if (user.status != "I") // If user is active, Authenticate the user. { bool result = UserManager.AuthenticateUser(credential, Session); if (result) //If username or password is matched with the database value, login the user. { TempData["message"] = ""; Session["UserId"] = user.UserId; Session["LoggedIn"] = true; if (user.IsAdmin) { return(RedirectToAction("AdminPage", "Admin")); } else { return(RedirectToAction("ProfilePage", "ProfilePage")); } } else { TempData["message"] = "Invalid login credentials"; return(View(credential)); } } else // If user is inactive, do not login the user. { TempData["invalid"] = "Your account has been banned"; return(RedirectToAction("Index", "Home")); } }
/// <summary> /// Makes a new instance of user in the database. /// </summary> /// <param name="value"></param> /// <returns></returns> // POST: api/User public HttpResponseMessage Post([FromBody] User value) { int id; UserPersistence userPersistance = new UserPersistence(); id = userPersistance.SaveUser(value); HttpResponseMessage response = new HttpResponseMessage(); response = Request.CreateResponse(HttpStatusCode.Created); response.Headers.Location = new Uri(Request.RequestUri, String.Format("User/{0}", id)); return(response); }
public static User[] GetAllUsers() { List <User> users = UserPersistence.GetAllUsers(); if (users != null) { return(UserPersistence.GetAllUsers().ToArray()); } else { return(new User[0]); } }
//GET: api/User/5 public User Get(int id) { UserPersistence u = new UserPersistence(); User User = u.GetUser(id); if (User == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); } return(User); }
public ActionResult ResetPassword(string UserId) { string password = UserPersistence.ResetPassword(UserId.Replace("'", "'")); if (password != null) { ViewBag.message = UserId + "'s password has changed. New password is: " + password; } else { ViewBag.message = "There was a problem with transaction. Please try again."; } return(View("ResetUserPassword", UserPersistence.GetAllUsers())); }
public User Get(int id) { UserPersistence userPersistance = new UserPersistence(); User user = userPersistance.GetUser(id); if (user.Id != 0) { return(user); } else { return(null); } }
public ActionResult ChangeStatus(string Status, string UserId) { bool result = UserPersistence.ChangeUserStatus(UserId.Replace("'", "'"), Status.Replace("'", "'")); if (result) { ViewBag.message = "Transaction Completed."; } else { ViewBag.message = "Transaction Failed. Try Again."; } return(View("ChangeUserStatus", UserPersistence.GetAllUsers())); }
/// <summary> /// Cria um novo User /// </summary> /// <param name="Name">Nome do usuario</param> /// <param name="Email">Email do usuario</param> /// <returns>True se a operacao deu certo, False ao contrario</returns> public bool Create(string name, string email) { // Cria um novo usuario User user = new User(); user.Name = name; user.Email = email; // Persiste na base de dados o novo usuario UserPersistence userPersistence = new UserPersistence(); bool result = userPersistence.Insert(user); return(result); }
public static UserPersistence MapUserEntityToUserPersistence(User user) { if (user == null) { return(null); } UserPersistence retVal = new UserPersistence() { Id = user.Id, Username = user.Username, Jmbg = user.Jmbg, Name = user.Name, Password = user.Password, Surname = user.Surname }; return(retVal); }