Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class UserLogin
- {
- public static string userName
- {
- get { return Convert.ToString(HttpContext.Current.Session["LoggedUser"]); }
- set { HttpContext.Current.Session["LoggedUser"] = value; }
- }
- public static string userPass
- {
- get { return Convert.ToString(HttpContext.Current.Session["LoggedPass"]); }
- set { HttpContext.Current.Session["LoggedPass"] = value; }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Web;
- using System.Web.Mvc;
- using LoginFormMVC.Models;
- namespace LoginFormMVC.Controllers
- {
- public class HomeController : Controller
- {
- public ActionResult Index()
- {
- return View();
- }
- public ActionResult About()
- {
- ViewBag.Message = "Your application description page.";
- return View();
- }
- public ActionResult Contact()
- {
- ViewBag.Message = "Your contact page.";
- return View();
- }
- public ActionResult LogIn()
- {
- return View("About");
- }
- [HttpPost]
- [ValidateAntiForgeryToken]
- public ActionResult LogIn(UserLogin u)
- {
- using (OTR2WCF.OTR2ServiceClient service = new OTR2WCF.OTR2ServiceClient())
- {
- var strResult = service.LoginUserJSON(LoginFormMVC.Models.UserLogin.userName, LoginFormMVC.Models.UserLogin.userName);
- u = null;
- if ((strResult != "[]") && (strResult.StartsWith("Error: ") == false))
- {
- UserLogin.userName = LoginFormMVC.Models.UserLogin.userName;
- UserLogin.userPass = LoginFormMVC.Models.UserLogin.userName;
- ModelState.AddModelError("", "Correct username and password");
- }
- else
- {
- ModelState.AddModelError("", "Wrong username or password");
- }
- }
- return View();
- }
- }
- }
- @model LoginFormMVC.Models.UserLogin
- @{
- ViewBag.Title = "LogIn";
- }
- <h2>LogIn</h2>
- @using (Html.BeginForm("LogIn", "Home", FormMethod.Post))
- {
- @Html.AntiForgeryToken()
- <div class="form-horizontal">
- <h4>UserLogin</h4>
- <hr />
- @Html.ValidationSummary(true, "", new { @class = "text-danger" })
- <div class="form-group">
- @Html.LabelFor(model => LoginFormMVC.Models.UserLogin.userName, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => LoginFormMVC.Models.UserLogin.userName, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => LoginFormMVC.Models.UserLogin.userName, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- @Html.LabelFor(model => LoginFormMVC.Models.UserLogin.userPass, htmlAttributes: new { @class = "control-label col-md-2" })
- <div class="col-md-10">
- @Html.EditorFor(model => LoginFormMVC.Models.UserLogin.userPass, new { htmlAttributes = new { @class = "form-control" } })
- @Html.ValidationMessageFor(model => LoginFormMVC.Models.UserLogin.userPass, "", new { @class = "text-danger" })
- </div>
- </div>
- <div class="form-group">
- <div class="col-md-offset-2 col-md-10">
- <button type="submit">New Request</button>
- </div>
- </div>
- </div>
- }
- <div>
- @Html.ActionLink("Back to List", "Index")
- </div>
- @section Scripts {
- @Scripts.Render("~/bundles/jqueryval")
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement