public ActionResult Edit(string id) { UserModel user = new UserModel(); user.GetUser( id); return View(user); }
public bool isValid(string validate_username, string validate_password, bool rememberMe) { UserModel UserOnline = new UserModel(); FakeUser accessfakeuser = new FakeUser(); JObject user; user = accessfakeuser.my_fake_login(validate_username, validate_password); try { if (user == null) { return false; } else { UserModel loggedUser = new UserModel(); loggedUser.Parse(user); _id = loggedUser._id; CreateCookie(loggedUser, rememberMe); HttpContext.Current.Session.Add("loggedUser", loggedUser); return true; } } catch (Exception ex) { return false; } }
// // GET: /User/ public ActionResult Index() { UserModel user = new UserModel(); user.GetUsers("/trainer"); return View(user); }
public void Test_createUser() { UserModel user = new UserModel(); user.UserName = "******" + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; user.firstName ="fn"+ DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; user.lastName = "ln" + DateTime.Now.Month + DateTime.Now.Day + DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second; user.Password="******"; user.Email = "*****@*****.**"; Assert.AreEqual(true, user.UserRegister()); bool Recived = user.GetUser(user._id); Assert.AreEqual(true, Recived); string nameTempUser = string.Empty; Random my_random = new Random(DateTime.Now.Millisecond); int num_random = my_random.Next(0, 99); nameTempUser = "******" + num_random; user.firstName = nameTempUser; if (user.UserSave()) { user.GetUser( user._id); Assert.AreEqual(nameTempUser, user.firstName); } Assert.IsTrue(user.UserDelete( user._id )); }
public ActionResult Delete() { UserModel User = new UserModel(); User = (UserModel)Session["loggedUser"]; FormsAuthentication.SignOut(); User.UserDelete( User._id ); return Redirect("Home/index"); }
public void CreateCookie(UserModel user , bool rememberMe ) { var serializer = new JavaScriptSerializer(); string userData = serializer.Serialize(user); FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.UserName, DateTime.Now, DateTime.Now.AddYears(1), rememberMe, userData); string encryptedTicket = FormsAuthentication.Encrypt(ticket); HttpCookie mycookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); if (ticket.IsPersistent) { mycookie.Expires = ticket.Expiration; mycookie.HttpOnly = true; } HttpContext.Current.Response.Cookies.Add(mycookie); }
public ActionResult Edit(string id, UserModel user) { try { // TODO: Add update logic here if (user.UserSave()) { return RedirectToAction("/Home/index"); } else { return View("/user/Create", User); } } catch { return View(); } }
public static void my_AuthenticateRequest() { HttpCookie authCookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName]; if (authCookie != null) { // Get the forms authentication ticket. FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(authCookie.Value); var identity = new GenericIdentity(authTicket.Name, "Forms"); // Get the custom user data encrypted in the ticket. string userData = ((FormsIdentity)(HttpContext.Current.User.Identity)).Ticket.UserData; // Deserialize the json data and set it on the custom principal. var serializer = new JavaScriptSerializer(); UserModel loginUser = (UserModel)serializer.Deserialize(userData, typeof(UserModel)); UserModel loggedUser = new UserModel(); loggedUser.GetUser(loginUser._id); HttpContext.Current.Session.Add("loggedUser", loggedUser); // Set the context user. } }
public ActionResult New(UserModel User) { try { if (User.UserRegister()) { return Redirect("/Home/Index"); } else { return View(User); } } catch { return Redirect("Home"); } }