public ActionResult Login(ViewModels.LoginViewModel login) { if (login.Username != Username || login.Password != Password) { SetErrorNotification("Login error"); return(View(login)); } var claims = new List <Claim>(); claims.Add(new Claim(ClaimTypes.NameIdentifier, UserId.ToString())); claims.Add(new Claim(ClaimTypes.Name, Username)); claims.Add(new Claim(ClaimTypes.Role, Role)); var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); var props = new AuthenticationProperties { IsPersistent = login.RememberMe }; HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, principal, props).Wait(); if (string.IsNullOrEmpty(login.ReturnUrl) || login.ReturnUrl == "/") { return(RedirectToAction("Index", "Default")); } else { return(Redirect(login.ReturnUrl)); } }
public LoginView() { BindingContext = new ViewModels.LoginViewModel(); Entry email = new Entry(); email.Placeholder = "*****@*****.**"; Entry senha = new Entry(); senha.Placeholder = "senha"; senha.IsPassword = true; Button btnLogar = new Button(); btnLogar.Text = "Logar"; //myButton.SetBinding(Button.CommandProperty, new Binding("ContatoCommand", 0)); btnLogar.SetBinding(Button.CommandProperty, new Binding("PrincipalCommand")); Content = new StackLayout { Children = { new StackLayout() { Children = { email, senha, btnLogar } } } }; }
public LoginPage() { Xamarin.Forms.NavigationPage.SetHasNavigationBar(this, false); //DESATIVA A BARRA DE NAVEGAÇÃO InitializeComponent(); this.BindingContext = this.viewModel = new ViewModels.LoginViewModel(this); }
public async Task <ActionResult> Login(ViewModels.LoginViewModel login, string returnUrl) { if (ModelState.IsValid) { var sm = await _sm.PasswordSignInAsync(login.Username, login.Password, true, false); if (sm.Succeeded) { if (string.IsNullOrWhiteSpace(returnUrl)) { return(RedirectToAction("Trips", "App")); } else { return(Redirect(returnUrl)); } } else { ModelState.AddModelError("", "User/ Password incorrect! "); } } return(View()); }
public async Task <IHttpActionResult> Login(ViewModels.LoginViewModel model) { //if (!this.ModelState.IsValid) //{ // return this.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 this.AppSignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout : false); switch (result) { case SignInStatus.Success: var user = await this.AppUserManager.FindByNameAsync(model.Email); var request = HttpContext.Current.Request; var tokenServiceUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath + "/Token"; using (var client = new HttpClient()) { var requestParams = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("grant_type", "password"), new KeyValuePair <string, string>("username", model.Email), new KeyValuePair <string, string>("password", model.Password) }; var requestParamsFormUrlEncoded = new FormUrlEncodedContent(requestParams); var tokenServiceResponse = await client.PostAsync(tokenServiceUrl, requestParamsFormUrlEncoded); var responseString = await tokenServiceResponse.Content.ReadAsStringAsync(); var responseCode = tokenServiceResponse.StatusCode; var jsSerializer = new System.Web.Script.Serialization.JavaScriptSerializer(); var responseData = jsSerializer.Deserialize <Dictionary <string, string> >(responseString); var authToken = responseData["access_token"]; var userName = responseData["userName"]; // Save bearer token to the database userSessionService.CreateUserSession(userName, authToken); // Cleanup: delete expired sessions from the database userSessionService.DeleteExpiredSessions(); return(Json(new { status = true, token = authToken })); } case SignInStatus.LockedOut: return(Json(new { status = false, error = "Lockout" })); case SignInStatus.RequiresVerification: return(Json(new { status = false, error = "" })); case SignInStatus.Failure: default: this.ModelState.AddModelError("", "Invalid login attempt."); return(Json(new { status = false, error = "Invalid login attempt" })); } }
//[ValidateAntiForgeryToken] public async Task <IActionResult> Login(ViewModels.LoginViewModel login) { if (ModelState.IsValid) { var pass = login.Password /*.Crypt()*/; var result = await signInManager.PasswordSignInAsync(login.Username, pass, login.RememberMe, false); if (result.Succeeded) { if (!string.IsNullOrEmpty(login.ReturnUrl) && Url.IsLocalUrl(login.ReturnUrl)) { return(Redirect(login.ReturnUrl)); } else { return(RedirectToAction("Index", "Home")); } } else { ModelState.AddModelError("", "Неправильные имя пользователя и (или) пароль."); } } return(View(login)); }
public LoginView() { InitializeComponent(); ViewModels.LoginViewModel _loginViewModel = new ViewModels.LoginViewModel(); this.DataContext = _loginViewModel; _loginViewModel.CurrentLoginWindow = this; }
public async Task <IActionResult> LogIn(ViewModels.LoginViewModel viewModel) { var isSignIn = signInManager.IsSignedIn(User); if (isSignIn) { return(RedirectToAction(actionName: "Index", controllerName: "Home")); } ViewBag.returnUrl = viewModel.ReturnUrl; if (ModelState.IsValid) { var result = await signInManager.PasswordSignInAsync (viewModel.Username, viewModel.Password, isPersistent : viewModel.RememberMe, lockoutOnFailure : true); if (result.Succeeded) { if (!string.IsNullOrWhiteSpace(viewModel.ReturnUrl) && Url.IsLocalUrl(viewModel.ReturnUrl)) { return(Redirect(viewModel.ReturnUrl)); } return(RedirectToAction(actionName: "Index", controllerName: "Home")); } if (result.IsLockedOut) { ViewBag.ErrorMessage = Resources.Messages.LockOutError; return(View(viewModel)); } ModelState.AddModelError("", Resources.Messages.WrongPasswordError); } return(View(model: viewModel)); }
public LoginPage() { NavigationPage.SetHasNavigationBar(this, false); InitializeComponent(); BindingContext = new ViewModels.LoginViewModel(); }
public LoginPage() { InitializeComponent(); BindingContext = new ViewModels.LoginViewModel(); usu.Text = string.Empty; sen.Text = string.Empty; }
public async Task <IActionResult> Login(ViewModels.LoginViewModel model, string ReturnUrl) { if (ModelState.IsValid) { var result = await signInManager.PasswordSignInAsync( userName : model.Email, password : model.Password, isPersistent : model.RememberMe, lockoutOnFailure : false); if (result.Succeeded) { if (!String.IsNullOrEmpty(ReturnUrl) && Url.IsLocalUrl(ReturnUrl)) { return(LocalRedirect(ReturnUrl)); } else { return(RedirectToAction("index", "home")); } } ModelState.AddModelError(string.Empty, "Invalid Login Attempt"); } if (model.ExternalLogins == null) { model.ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); } if (String.IsNullOrEmpty(model.ReturnUrl) && (!String.IsNullOrEmpty(ReturnUrl))) { model.ReturnUrl = ReturnUrl; } return(View(model)); } // End Login Post
public IActionResult Login(LoginViewModel loginViewModel) { var db = new TheChampionContext(); var account = db.Accounts.FirstOrDefault(a => a.LoginName == loginViewModel.LoginName); if (account != null) { if (account.LoginPassword == loginViewModel.LoginPassword) { return(Redirect("/home/dashboard/" + account.AccountId)); } else { var vm = new ViewModels.LoginViewModel { LoginName = "", LoginPassword = "", Error = "Girdiğiniz şifre hatalı, lütfen tekrar deneyiniz." }; return(View(vm)); } } else { var vm = new ViewModels.LoginViewModel { LoginName = "", LoginPassword = "", Error = "Kullanıcı adı bulunamadı, lütfen tekrar deneyiniz." }; return(View(vm)); } }
public Login() { InitializeComponent(); _vm = new ViewModels.LoginViewModel(); this.DataContext = _vm; NameTextBox.Text = "shuayb"; PasswordBox.Password = "******"; NameTextBox.Focus(); //using (var db = new AlphaElectricEntitiesDB()) //{ // //Adding New User // AlphaElectric_DataAccessLayer.Login newUser = new AlphaElectric_DataAccessLayer.Login() // { // Username = "******", // Name = "Shuayb Ashraf", // Password = Hashing.HashPassword("12345") // }; // db.Logins.Add(newUser); // db.SaveChanges(); //} }
public async Task <string> LoginUser(ViewModels.LoginViewModel model) { var user = await this._userManager.FindByNameAsync(model.UserName); if (user != null && await this._userManager.CheckPasswordAsync(user, model.Password)) { var claim = new[] { new Claim(JwtRegisteredClaimNames.Sub, user.UserName) }; var signingKey = new SymmetricSecurityKey( Encoding.UTF8.GetBytes(this._configuration["Jwt:SigningKey"])); var expiryInMinutes = Convert.ToInt32(this._configuration["Jwt:ExpiryInMinutes"]); var token = new JwtSecurityToken( issuer: this._configuration["Jwt:Site"], audience: this._configuration["Jwt:Site"], expires: DateTime.UtcNow.AddMinutes(expiryInMinutes), signingCredentials: new Microsoft.IdentityModel.Tokens.SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256) ); return(new JwtSecurityTokenHandler().WriteToken(token)); } return(null); }
public LoginPage() { InitializeComponent(); LoginViewModel model = new ViewModels.LoginViewModel(); model.Requested = false; this.BindingContext = model; }
public IActionResult Login() { var vm = new ViewModels.LoginViewModel { LoginName = "", LoginPassword = "" }; return(View(vm)); }
public LoginPage(bool breach) { _viewModel = new ViewModels.LoginViewModel(); InitializeComponent(); if (breach) { DisplayAlert("Security Breach", "You've accessed the page not as an admin. You have been logged to enforce the security policy", "Affirmitive"); } BindingContext = _viewModel; }
public async Task <IActionResult> Login(string returnUrl) { ViewModels.LoginViewModel model = new ViewModels.LoginViewModel { ReturnUrl = returnUrl, ExternalLogins = (await signInManager.GetExternalAuthenticationSchemesAsync()).ToList() }; return(View(model)); }
public async Task <ActionResult> Login([FromBody] ViewModels.LoginViewModel model) { var token = await this._service.LoginUser(model); if (string.IsNullOrEmpty(token) || string.IsNullOrWhiteSpace(token)) { return(Unauthorized()); } return(Ok(token)); }
public async Task <IActionResult> Login([FromBody] ViewModels.LoginViewModel user) { IActionResult _result = new ObjectResult(false); GenericResult _authenticationResult = null; try { MembershipContext _userContext = _membershipService.ValidateUser(user.Username, user.Password); if (_userContext.User != null) { IEnumerable <Role> _roles = _userRepository.GetUserRoles(user.Username); List <Claim> _claims = new List <Claim>(); foreach (Role role in _roles) { Claim _claim = new Claim(ClaimTypes.Role, "Admin", ClaimValueTypes.String, user.Username); _claims.Add(_claim); } await HttpContext.Authentication.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(new ClaimsIdentity(_claims, CookieAuthenticationDefaults.AuthenticationScheme))); _authenticationResult = new GenericResult() { Succeeded = true, Message = "Authentication succeeded" }; } else { _authenticationResult = new GenericResult() { Succeeded = false, Message = "Authentication failed" }; } } catch (Exception ex) { _authenticationResult = new GenericResult() { Succeeded = false, Message = ex.Message }; _loggingRepository.Add(new Error() { Message = ex.Message, StackTrace = ex.StackTrace, DateCreated = DateTime.Now }); _loggingRepository.Commit(); } _result = new ObjectResult(_authenticationResult); return(_result); }
public async Task <RootLogin> LoginAsync(ViewModels.LoginViewModel loginViewModel) { var postContent = GetAccountPostContent(loginViewModel); var response = await client.PostAsync("Account/LoginAsync", postContent); var postResult = await response.Content.ReadAsStringAsync(); var userResult = JsonConvert.DeserializeObject <RootLogin>(postResult); return(userResult); }
public Microsoft.AspNetCore.Mvc.IActionResult Learn04(ViewModels.LoginViewModel viewModel) { string state = string.Empty; if (ModelState.IsValid) { state = $"Login for {viewModel.Username} with password {viewModel.Password} successed..."; ViewData["status"] = state; } return(View(model: viewModel)); }
private StringContent GetAccountPostContent(ViewModels.LoginViewModel loginViewModel) { var content = new { Email = loginViewModel.Email, Password = loginViewModel.Password, PasswordConfirmation = loginViewModel.Password, IdLanguages = App.IdLanguages, IdSystems = App.IdSystems }; return(new StringContent(JsonConvert.SerializeObject(content), Encoding.UTF8, "application/json")); }
public async Task <IActionResult> Register([FromBody] ViewModels.LoginViewModel model) { var user = new AppUser { UserName = model.Email, Email = model.Email }; var result = await _userManager.CreateAsync(user, model.Password); if (result.Succeeded) { return(Ok()); } return(BadRequest(result.Errors)); }
private async void txtConfirmNewPassword_Completed(object sender, EventArgs e) { try { using (Acr.UserDialogs.UserDialogs.Instance.Loading("")) { var obj = sender as ChangePassword; //email = txtUsername.Text.Trim(); email = GlobalStaticFields.Username; CurPass = txtCurrentPassword.Text.Trim(); NewPass = txtNewPassword.Text.Trim(); ConfirmNewPass = txtConfirmNewPassword.Text.Trim(); lvvm = new ViewModels.LoginViewModel() { User = new Models.UserInfo { Username = email, Password = CurPass, NewPassword = NewPass, ConfirmNewPassword = ConfirmNewPass } }; if (IsEntryValid().Result) { bool resp = await lvvm.ChangePassword(); if (resp) { if (await DisplayAlert("Cool", "Password Changed", "OK", "Home")) { await Application.Current.MainPage.Navigation.PopToRootAsync(true); } else { await Application.Current.MainPage.Navigation.PopToRootAsync(true); } } } else { await DisplayAlert("Info", MessageToUser, "OK"); } } } catch (Exception ex) { var log = ex; await DisplayAlert("Error", "Error occured", "OK"); } }
public Login() { BindingContext = new ViewModels.LoginViewModel(Navigation); var layout = new StackLayout { Padding = 10 }; var label = new Label { Text = "Welcome to PrinceBook. Please Login.", Font = Font.BoldSystemFontOfSize(NamedSize.Large), TextColor = Color.White, VerticalOptions = LayoutOptions.CenterAndExpand, XAlign = TextAlignment.Center, YAlign = TextAlignment.Center, }; layout.Children.Add(label); var username = new Entry { Placeholder = "Username" }; username.SetBinding(Entry.TextProperty, new Binding("Username", BindingMode.TwoWay)); layout.Children.Add(username); var password = new Entry { Placeholder = "Password", IsPassword = true }; password.SetBinding(Entry.TextProperty, ViewModels.LoginViewModel.PasswordPropertyName); layout.Children.Add(password); var button = new Button { Text = "Log In", TextColor = Color.White }; button.Clicked += delegate { Helpers.Global.UserName = username.Text; Navigation.PushAsync(new Industry()); }; layout.Children.Add(button); Content = new ScrollView { Content = layout }; }
public async Task Login_ModelValidationFail_Returns400BadRequestAsync() { var loginViewModel = new ViewModels.LoginViewModel() { Email = "x", Password = "******", }; var response = await this.client.PostAsJsonAsync("auth/login", loginViewModel).ConfigureAwait(false); Assert.Equal(HttpStatusCode.BadRequest, response.StatusCode); var problemDetails = await response.Content.ReadAsAsync <ProblemDetails>(this.formatters).ConfigureAwait(false); Assert.Equal(StatusCodes.Status400BadRequest, problemDetails.Status); }
public async Task <IActionResult> Login([FromBody] ViewModels.LoginViewModel model) { var result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, false, false); if (result.Succeeded) { var appUser = _userManager.Users.SingleOrDefault(r => r.Email == model.Email); var token = new ViewModels.TokenViewModel() { Token = GenerateJwtToken(model.Email, appUser), TokenExpire = DateTime.Now.AddDays(Startup.TokenExpireDays) }; return(Ok(token)); } return(BadRequest()); }
public LoginPage() { InitializeComponent(); BindingContext = _viewModel = new ViewModels.LoginViewModel(); Email.Completed += (object sender, EventArgs e) => { Password.Focus(); }; Password.Completed += (object sender, EventArgs e) => { buttonLogin.IsEnabled = false; _viewModel.LoginCommand.Execute(null); buttonLogin.IsEnabled = true; }; }
public ActionResult Login() { if (System.Web.HttpContext.Current.Session["enseignant"] != null) { return(RedirectToAction("Index", "Enseignant", new { area = "" })); } else if (System.Web.HttpContext.Current.Session["parent"] != null) { return(RedirectToAction("Index", "Parent", new { area = "" })); } else if (System.Web.HttpContext.Current.Session["coordinateur"] != null) { return(RedirectToAction("Index", "Coordinateur", new { area = "" })); } else if (System.Web.HttpContext.Current.Session["administration"] != null) { return(RedirectToAction("Index", "Administration", new { area = "" })); } else if (System.Web.HttpContext.Current.Session["administrateur"] != null) { return(RedirectToAction("Index", "Root", new { area = "" })); } ViewModels.LoginViewModel login = new ViewModels.LoginViewModel(); login.type = new List <SelectListItem> { new SelectListItem { Text = "Administrateur", Value = "Administrateur" }, new SelectListItem { Text = "Enseignant", Value = "Enseignant" }, new SelectListItem { Text = "Parent", Value = "Parent" }, new SelectListItem { Text = "Coordinateur", Value = "Coordinateur" }, new SelectListItem { Text = "Administration", Value = "Administration" } }; return(View(login)); }
public LoginView() { InitializeComponent(); BindingContext = new ViewModels.LoginViewModel(); }