public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } // This doesn't count login failures towards account lockout // To enable password failures to trigger account lockout, change to shouldLockout: true var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); switch (result) { case SignInStatus.Success: var user = await UserManager.FindByEmailAsync(model.Email); UserTracking NewUser = new UserTracking(); NewUser.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; NewUser.user_Id = user.Id; NewUser.insert(NewUser); return RedirectToLocal(returnUrl); case SignInStatus.LockedOut: return View("Lockout"); case SignInStatus.RequiresVerification: return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe }); case SignInStatus.Failure: default: ModelState.AddModelError("", "Invalid login attempt."); return View(model); } }
public ActionResult Index(int? page, UserTracking U) { ModelState.SetModelValue("StartDate", new ValueProviderResult(DateTime.Now, null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDate", new ValueProviderResult(DateTime.Today, null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("StartDateHours", new ValueProviderResult("12", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateHours", new ValueProviderResult("11", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("StartDateMinutes", new ValueProviderResult("00", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateMinutes", new ValueProviderResult("50", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateAmPm", new ValueProviderResult("Pm", null, CultureInfo.InvariantCulture)); ViewBag.GetHours = U.GetHours(); ViewBag.GetMins = U.GetMins(); ViewBag.GetAmPm = U.GetAmPm(); DateTime startDate = U.StartDate; if (page.HasValue) { if (U.StartDateAmPm.ToUpper() == "PM") { U.StartDateHours = (U.StartDateHours % 12) + 12; } if (U.EndDateAmPm.ToUpper() == "PM") { U.EndDateHours = (U.EndDateHours % 12) + 12; } ModelState.SetModelValue("StartDateHours", new ValueProviderResult("12", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateHours", new ValueProviderResult("11", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("StartDateMinutes", new ValueProviderResult("00", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateMinutes", new ValueProviderResult("50", null, CultureInfo.InvariantCulture)); ModelState.SetModelValue("EndDateAmPm", new ValueProviderResult("Pm", null, CultureInfo.InvariantCulture)); DateTime StartDate = U.StartDate; TimeSpan ts = new TimeSpan(U.StartDateHours, U.StartDateMinutes, 0); startDate = startDate.Date + ts; DateTime EndDate = U.EndDate; TimeSpan ts1 = new TimeSpan(U.EndDateHours, U.EndDateMinutes, 0); EndDate = EndDate.Date + ts1; ViewBag.GetHours = U.GetHours(); ViewBag.GetMins = U.GetMins(); ViewBag.GetAmPm = U.GetAmPm(); if (U.RadioButtonSelectedValue == "1") { U.UserTrackingList = U.UserTrackingReport(); U.UserTrackingList = U.UserTrackingList.Where(a => a.TimeStamp >= startDate && a.TimeStamp <= EndDate).ToList(); U.PagedUserTrackingList = U.UserTrackingList.ToPagedList(page ?? 1, 10); return View(U); } else { U.SearchedDataList = U.SearchDataReport(); U.SearchedDataList = U.SearchedDataList.Where(a => a.TimeStamp >= startDate && a.TimeStamp <= EndDate).ToList(); U.PagedUserTrackingList = U.SearchedDataList.ToPagedList(page ?? 1, 10); return View(U); } } return View(); }
public List<UserTracking> UserTrackingReport() { List<UserTracking> UTList = new List<UserTracking>(); string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (MySqlConnection con = new MySqlConnection(cs)) { con.Open(); MySqlCommand cmd = new MySqlCommand("Sp_UserTrackingReport", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read()) { UserTracking UT = new UserTracking(); UT.IPAddress = rdr["IPAddress"].ToString(); UT.TimeStamp = Convert.ToDateTime(rdr["TimeIn"]); UT.user_Id = rdr["userid"].ToString(); UT.Name = rdr["Name"].ToString(); UT.CompanyName = rdr["CompanyName"].ToString(); UT.Email = rdr["Email"].ToString(); UT.PhoneNumber = rdr["PhoneNumber"].ToString(); UTList.Add(UT); } } return UTList; }
public void insert(UserTracking user) { string cs = ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString; using (MySqlConnection con = new MySqlConnection(cs)) { con.Open(); MySqlCommand cmd = new MySqlCommand("Sp_AddUserTracking", con); cmd.CommandType = System.Data.CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@_User_Id", user_Id); cmd.Parameters.AddWithValue("@_IPAddress", IPAddress); cmd.Parameters.AddWithValue("@_TimeStamp", DateTime.Now); cmd.ExecuteNonQuery(); } }
public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser { UserName = model.Email, Email = model.Email , Name =model.Name , PhoneNumber=model.PhoneNumber,PhoneNumber2 = model.PhoneNumber2, CompanyEmail = model.CompanyEmail ,CompanyName=model.CompanyName,Address = model.Address, Address2 = model.Address2, City =model.City, State=model.State,Zip=model.Zip,Fax=model.Fax}; var result = await UserManager.CreateAsync(user, model.Password); if (result.Succeeded) { await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false); UserTracking NewUser = new UserTracking(); NewUser.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; NewUser.user_Id = user.Id; NewUser.insert(NewUser); // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771 // Send an email with this link // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id); // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme); // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); return RedirectToAction("Index", "Home"); } AddErrors(result); } // If we got this far, something failed, redisplay form return View(model); }
protected void Session_Start(object sender, EventArgs e) { UserTracking NewUser = new UserTracking(); NewUser.IPAddress = Request.ServerVariables["REMOTE_ADDR"]; NewUser.insert(NewUser); }