Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ActionResult Login(string returnUrl)
- {
- ViewBag.ReturnUrl = returnUrl;
- return View();
- }
- //
- // POST: /Account/Login
- [HttpPost]
- [AllowAnonymous]
- [ValidateAntiForgeryToken]
- public ActionResult Login(LoginModel model, string returnUrl)
- {
- try
- {
- if (model.UserName == null && model.Password == null)
- {
- return View();
- }
- else
- {
- var errors = ModelState
- .Where(x => x.Value.Errors.Count > 0)
- .Select(x => new { x.Key, x.Value.Errors })
- .ToArray();
- if (Membership.ValidateUser(model.UserName, model.Password))
- {
- if (ModelState.IsValid && model.UserName != null && model.Password != null && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
- {
- UsersContext usercontext = new UsersContext();
- var profile = usercontext.UserProfiles.FirstOrDefault(d => d.UserName.Equals(model.UserName));
- if (profile != null)
- {
- Session["LogedUserFirstName"] = profile.FirstName;
- Session["Email"] = profile.Email;
- Session["Username"] = profile.UserName;
- Session["LastName"] = profile.LastName;
- Session["MobileNumber"] = profile.MobileNumber;
- if (Roles.IsUserInRole(model.UserName, "Admin"))
- {
- return RedirectToAction("Index", "Base");
- }
- else if (Roles.IsUserInRole(model.UserName, "User"))
- {
- return RedirectToAction("myProfile");
- }
- else {
- }
- }
- else if (model.UserName == null && model.Password == null) { }
- else if (model.UserName == null && model.Password != null) { }
- else if (model.UserName != null && model.Password == null) { }
- else
- {
- ViewBag.Message("Username does not exist...");
- return View(model);
- }
- }
- }
- else
- {
- ViewBag.Message = "Username or Password provided is incorrect...";
- return View();
- }
- }
- }
- catch
- {
- ViewBag.Message("OOPs.... Something went wrong");
- return View();
- }
- return View(model);
- }
- @if (ViewData.ModelState.IsValid)
- {
- if (ViewBag.Message != null)
- {
- <h6 style="color:#ff0000;width:350px;">@ViewBag.Message</h6>
- }
- }
- @using (Html.BeginForm("Login", "Account", FormMethod.Post, new { ReturnUrl = ViewBag.ReturnUrl }))
- {
- @Html.AntiForgeryToken()
- @Html.ValidationSummary(true)
- <fieldset id="login_form">
- <label class="block clearfix" style="text-align: left">
- <span class="block input-icon input-icon-right"><i class="ace-icon fa fa-user"></i>
- @Html.TextBoxFor(m => m.UserName, new { @class = "form-control", placeholder = "UserName" })
- <p id="log_valid">
- @Html.ValidationMessageFor(m => m.UserName)</p>
- </span>
- </label>
- <label class="block clearfix" style="text-align: left">
- <span class="block input-icon input-icon-right"><i class="ace-icon fa fa-lock"></i>
- @Html.PasswordFor(m => m.Password, new { @class = "form-control", placeholder = "Password" })
- <p id="log_valid">@Html.ValidationMessageFor(m => m.Password)</p>
- </span>
- </label>
- <div class="space" style="text-align: left">
- </div>
- <div class="clearfix">
- <label class="inline">
- <input type="checkbox" class="ace" checked= "@ViewBag.IsCheck" name="agreecheckbox" value="check" />
- <span class="lbl">Remember Me</span> <span>@ViewBag.Msg</span>
- </label>
- <button type="submit" class="width-35 pull-right btn btn-sm btn-primary" onclick="@("window.location.href='" + @Url.Action("AfterLogin", "Account"));" >
- <i class="ace-icon fa fa-key"></i><span class="bigger-110">Login</span>
- </button>
- <a href="@Url.Action("forgotPassword", "Account")">
- <h6>
- Forgot Password?</h6>
- </a>
- </div>
- </fieldset>
- }
- </div>
- <!-- /.widget-main -->
- </div>
- <!-- /.widget-body -->
- </div>
- <!-- /.login-box -->
- <div id="forgot-box" class="forgot-box widget-box no-border">
- <div class="widget-body">
- <div class="widget-main">
- <h4 class="header red lighter bigger">
- <i class="ace-icon fa fa-key"></i>Retrieve Password
- </h4>
- <div class="space-6">
- </div>
- <p>
- Enter your Username
- </p>
- <form>
- <fieldset>
- <label class="block clearfix">
- <span class="block input-icon input-icon-right">
- <input type="UserName" class="form-control" placeholder="Email" />
- <i class="ace-icon fa fa-user"></i></span>
- </label>
- <div class="clearfix">
- <button type="button" class="width-35 pull-right btn btn-sm btn-danger" onclick="location.href='@Url.Action("forgotPassword", "Account")'">
- Send Me <i class="ace-icon fa fa-lightbulb-o"></i>
- </button>
- </div>
- </fieldset>
- </form>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement