public IActionResult Login() { IdentityViewModel identityViewModel = new IdentityViewModel(); identityViewModel.invalid = false; return(View(identityViewModel)); }
public async Task <IActionResult> Token([FromBody] IdentityViewModel model) { SignInResult result = await _signInManager.PasswordSignInAsync(model.Email, model.Password, true, false); if (!result.Succeeded) { return(Unauthorized()); } ApplicationUser user = await _userManager.FindByEmailAsync(model.Email); CurrentUserId = user.Id; List <Claim> claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, model.Email), }; DateTime now = DateTime.UtcNow; JwtSecurityToken jwt = new JwtSecurityToken( issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, notBefore: now, claims: claims, expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)), signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); string encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); return(Ok(encodedJwt)); }
public async Task TestLogOnLogOffWhenLoggedOn() { LogOnIdentity passphrase = new LogOnIdentity("p"); LogOnIdentity id = passphrase; Resolve.FileSystemState.KnownPassphrases.Add(id.Passphrase); await Resolve.KnownIdentities.SetDefaultEncryptionIdentity(id); bool wasLoggingOn = false; IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { wasLoggingOn = true; return(Task.FromResult <object>(null)); }; Assert.That(Resolve.KnownIdentities.IsLoggedOn, Is.True); await ivm.LogOnLogOff.ExecuteAsync(null); Assert.That(wasLoggingOn, Is.False); Assert.That(Resolve.KnownIdentities.IsLoggedOn, Is.False); }
public async Task <IActionResult> Token([FromBody] IdentityViewModel request) { //Добавить проверку срока жизни PIN-кода if (!ValidateUser(request)) { return(Unauthorized()); } var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, request.Login), }; var identity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); var now = DateTime.UtcNow; var jwt = new JwtSecurityToken( issuer: "FamilIntegrationService", audience: "IntegrationUser", notBefore: now, claims: identity.Claims, expires: now.Add(TimeSpan.FromHours(24)), signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes("gfdiog40-]kgf-043uo")), SecurityAlgorithms.HmacSha256)); var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); return(Ok(encodedJwt)); }
public async Task <IActionResult> Login(string returnUrl, string confirmed, string invalid) { IdentityViewModel identityViewModel = new IdentityViewModel(); //identityViewModel.invalid = false; if (!string.IsNullOrEmpty(confirmed)) { identityViewModel.confirmed = confirmed; } if (!string.IsNullOrEmpty(invalid)) { if (invalid == "upw") { identityViewModel.invalid = "Username and password combination wrong"; } else { identityViewModel.invalid = "Email not confirmed yet"; } } identityViewModel.login.ReturnUrl = returnUrl; identityViewModel.login.ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); return(View(identityViewModel)); }
public async Task AskForNewLogOnPassphraseWithKnownIdentity() { Passphrase passphrase = new Passphrase("aaa"); Passphrase id = passphrase; Resolve.FileSystemState.KnownPassphrases.Add(id); IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { if (!e.IsAskingForPreviouslyUnknownPassphrase) { e.IsAskingForPreviouslyUnknownPassphrase = true; } e.Passphrase = new Passphrase("aaa"); return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(null); Assert.That(ivm.LogOnIdentity.Passphrase.Text, Is.EqualTo("aaa")); Assert.That(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint, Is.EqualTo(passphrase.Thumbprint)); Assert.That(Resolve.FileSystemState.KnownPassphrases.Count(), Is.EqualTo(1)); }
public async Task AskForNewLogOnPassphrase() { Passphrase defaultPassphrase = null; Resolve.FileSystemState.KnownPassphrases.Add(Passphrase.Empty); IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { if (!e.IsAskingForPreviouslyUnknownPassphrase) { e.IsAskingForPreviouslyUnknownPassphrase = true; e.Passphrase = new Passphrase("xxx"); return(Task.FromResult <object>(null)); } defaultPassphrase = e.Passphrase; e.Passphrase = new Passphrase("aaa"); return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(null); Assert.That(defaultPassphrase, Is.EqualTo(new Passphrase("xxx"))); Assert.That(ivm.LogOnIdentity.Passphrase.Text, Is.EqualTo("aaa")); Assert.That(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint, Is.EqualTo(new Passphrase("aaa").Thumbprint)); Passphrase id = Resolve.FileSystemState.KnownPassphrases.FirstOrDefault(i => i.Thumbprint == new Passphrase("aaa").Thumbprint); Assert.That(id.Thumbprint, Is.EqualTo(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint)); }
public async Task <IActionResult> Token([FromBody] IdentityViewModel model) { var identity = await GetIdentity(model.Username, model.Password); if (identity == null) { return(Unauthorized()); } var now = DateTime.UtcNow; // создаем JWT-токен var jwt = new JwtSecurityToken( issuer: AuthOptions.ISSUER, audience: AuthOptions.AUDIENCE, notBefore: now, claims: identity.Claims, expires: now.Add(TimeSpan.FromMinutes(AuthOptions.LIFETIME)), signingCredentials: new SigningCredentials(AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); var response = new { access_token = encodedJwt, username = identity.Name }; return(Ok(response)); }
public async Task <IActionResult> LoginIn(IdentityViewModel identityViewModel, string ReturnUrl) { identityViewModel.login.ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList(); if (ModelState.IsValid) { var user = await _userManager.FindByEmailAsync(identityViewModel.login.LoginEmail); if (user != null && !user.EmailConfirmed && (await _userManager.CheckPasswordAsync(user, identityViewModel.login.LoginPassword))) { return(RedirectToAction("login", new { invalid = "enc" })); } return(RedirectToAction("SendSms", "Twilio", new { userId = user.Id, isPersistent = identityViewModel.login.RememberMe })); //var result = await _signInManager.PasswordSignInAsync(identityViewModel.login.LoginEmail, identityViewModel.login.LoginPassword, identityViewModel.login.RememberMe, false); //if (result.Succeeded) //{ // if (!string.IsNullOrEmpty(ReturnUrl)) // { // return Redirect(ReturnUrl); // } // else // { // return RedirectToAction("Index", "Home", new { Area = "Client" }); // } //} } return(RedirectToAction("login", new { invalid = "upw" })); }
public async Task <IActionResult> Token([FromBody] IdentityViewModel request) { if (!ValidateUser(request)) { return(Unauthorized()); } var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, request.Login), }; var identity = new ClaimsIdentity(claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); var now = DateTime.UtcNow; var jwt = new JwtSecurityToken( issuer: "MonitoringHelperService", audience: "MonitoringUser", notBefore: now, claims: identity.Claims, expires: now.Add(TimeSpan.FromHours(24)), signingCredentials: new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes("nr490jf390353hj9")), SecurityAlgorithms.HmacSha256)); var encodedJwt = new JwtSecurityTokenHandler().WriteToken(jwt); return(Ok(encodedJwt)); }
private bool ValidateUser(IdentityViewModel request) { CreateTableIfNotExists(); var passwordHash = GetPasswordHash(request.Password); using (var conn = new NpgsqlConnection(DBProvider.GetConnectionString())) { conn.Open(); return((Int64) new NpgsqlCommand(String.Format(@"Select COUNT(1) from ""public"".""User"" Where ""Login"" = '{0}' and ""Password"" = '{1}'", request.Login, passwordHash), conn).ExecuteScalar() > 0); } }
public async Task <IActionResult> IsEmailInUse(IdentityViewModel identityViewModel) { var user = await _userManager.FindByEmailAsync(identityViewModel.signup.CustomerEmail); if (user == null) { return(Json(true)); } else { return(Json("Email is already in use")); } }
public void Edit_Valid() { //Arrange IdentityViewModel model = new IdentityViewModel() { GUID = "test" }; //Act var result = (ViewResult)controllerWEB.Edit(model); //Assert Assert.AreEqual("", result.ViewName); }
public ActionResult Edit(IdentityViewModel model, HttpPostedFileBase filedata = null) { if (ModelState.IsValid && filedata != null) { var user = service.GetSimple(model.ID); user.Picture = service.SaveImage(filedata, user.Picture); service.Edit(user); return(RedirectToAction("Index")); } else { return(View(model)); } }
public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IdentityViewModel model = (IdentityViewModel)service.GetSimple(id); if (model != null) { return(View(model)); } return(HttpNotFound()); }
private async void WebView_ScriptNotifyAsync(object sender, NotifyEventArgs e) { bool validUri = false; switch (e.CallingUri.LocalPath.ToString()) { case "/PacFORMS/XSC_ICS-213_Message_v070628.html": validUri = true; break; case "/PacFORMS/XSC_EOC-213RR_v1708.html": validUri = true; break; case "/PacFORMS/XSC_OA_MuniStatus_v20130101.html": validUri = true; break; //case default: use C# 7.1 // // Unauthorized page // return; } if (!validUri) { return; } // open payload in SimpleMessage in FormsPage. Fill in To and send string payload = e.Value; IdentityViewModel viewModel = IdentityViewModel.Instance; PacketMessage packetMessage = new PacketMessage() { //ReceivedTime = DateTime.Parse(messageReceivedTime.Text), MessageFrom = viewModel.UseTacticalCallsign ? viewModel.TacticalCallsign : viewModel.UserCallsign, MessageNumber = Utilities.GetMessageNumberPacket(), MessageBody = payload, //TNCName = "E-Mail-" + Singleton<TNCSettingsViewModel>.Instance.CurrentMailAccount.MailUserName, }; string folderPath = SharedData.UnsentMessagesFolder.Path; //CommunicationsService communicationsService = CommunicationsService.CreateInstance(); //await communicationsService.CreatePacketMessageFromMessageAsync(packetMessage); await CreatePacketMessageFromMessageAsync(packetMessage, folderPath); string packetMessagePath = Path.Combine(folderPath, packetMessage.FileName); NavigationService.Navigate(typeof(CountyFormsPage), packetMessagePath); }
public void Edit_Invalid() { //Arrange IdentityViewModel model = new IdentityViewModel() { }; controllerWEB.ModelState.AddModelError("Error", "Что-то пошло не так"); //Act var result = (ViewResult)controllerWEB.Edit(model); //Assert Assert.AreEqual("", result.ViewName); }
public SendFormDataControl() { InitializeComponent(); ScanControls(messageInfo); //(string bbs, string tnc, string from) = Utilities.GetProfileDataBBSStatusChecked(); ViewModel.MessageBBS = Utilities.GetSenderBBSStatusChecked(); ViewModel.MessageTNC = PacketSettingsViewModel.Instance.CurrentProfile.TNC; ViewModel.MessageTo = PacketSettingsViewModel.Instance.CurrentProfile.SendTo; IdentityViewModel instance = IdentityViewModel.Instance; ViewModel.MessageFrom = instance.UseTacticalCallsign ? instance.TacticalCallsign : instance.UserCallsign; ViewModelBase = ViewModel; }
public async Task <IActionResult> Index() { var user = await _context.Users.Where(x => x.UserName == User.Identity.Name).FirstOrDefaultAsync(); if (user == null) { return(View(new IdentityViewModel())); } var model = new IdentityViewModel() { UserId = user.Id }; return(View(model)); }
public async Task <IActionResult> Login(IdentityViewModel identityViewModel) { if (ModelState.IsValid) { var result = await _signInManager.PasswordSignInAsync(identityViewModel.login.LoginEmail, identityViewModel.login.LoginPassword, identityViewModel.login.RememberMe, false); if (result.Succeeded) { return(RedirectToAction("Index", "Home", new { Area = "Client" })); } ModelState.AddModelError("invalid", "Tài khoản hoặc mật khẩu không đúng"); identityViewModel.invalid = true; } return(View(identityViewModel)); }
public async Task AskForLogOnOrDecryptPassphraseActionNotActiveFile() { IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); LogOnIdentity id = null; ivm.LoggingOnAsync = (e) => { id = e.Identity; e.Passphrase = new Passphrase("p"); return(Task.FromResult <object>(null)); }; await ivm.AskForDecryptPassphrase.ExecuteAsync(@"C:\Folder\File1-txt.axx"); Assert.That(ivm.LogOnIdentity.Passphrase.Text, Is.EqualTo("p")); Assert.That(id.Passphrase.Thumbprint, Is.EqualTo(Passphrase.Empty.Thumbprint)); }
public async Task TestLogOnLogOffWhenLoggedOffAndNoIdentitiesWithCancel() { IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Cancel = true; return(Task.FromResult <object>(null)); }; ivm.LogOnIdentity = new LogOnIdentity("testing"); await ivm.LogOnLogOff.ExecuteAsync(null); Assert.That(Resolve.KnownIdentities.IsLoggedOn, Is.False, "Not logged on."); Assert.That(Resolve.FileSystemState.KnownPassphrases.Count(), Is.EqualTo(0)); Assert.That(ivm.LogOnIdentity == LogOnIdentity.Empty); }
public IActionResult GetToken([FromBody] IdentityViewModel model) { var user = _repository.GetUser(model.UserName, model.Password); if (user == null) { return(Unauthorized()); } // Todo: разнести код ClaimsIdentity identity = null; var claims = new List <Claim> { new Claim(ClaimsIdentity.DefaultNameClaimType, user.Name), new Claim(ClaimsIdentity.DefaultRoleClaimType, EnumHelper.RoleToString(user.Role)) }; identity = new ClaimsIdentity( claims, "Token", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType); var dateTime = DateTime.Now; var token = new JwtSecurityToken( issuer: AuthOptions.Issuer, audience: AuthOptions.Audience, notBefore: dateTime, claims: identity.Claims, expires: dateTime.Add(TimeSpan.FromMinutes(AuthOptions.Lifetime)), signingCredentials: new SigningCredentials( AuthOptions.GetSymmetricSecurityKey(), SecurityAlgorithms.HmacSha256)); var encodedToken = new JwtSecurityTokenHandler().WriteToken(token); var result = new { token = encodedToken, username = identity.Name }; return(Ok(result)); }
public async Task ShouldSaveIdentity() { var expectedIdentity = new IdentityViewModel { Id = Guid.NewGuid(), Name = "New identity", Token = "Secret", ExpirationDate = DateTime.UtcNow }; SetupCreateOrUpdate <Identity, IdentityViewModel>(expectedIdentity); await _handler.Handle(new SaveIdentity { Identity = expectedIdentity }); RepositoryMock.VerifyAll(); }
public async Task AskForLogOnPassphraseActionWithCancel() { LogOnIdentity key = new LogOnIdentity("ppp"); LogOnIdentity id = key; IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Cancel = true; return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(id); Assert.That(ivm.LogOnIdentity == LogOnIdentity.Empty); Assert.That(Resolve.KnownIdentities.DefaultEncryptionIdentity == LogOnIdentity.Empty); }
public async Task AskForLogOnPassphraseAction() { LogOnIdentity key = new LogOnIdentity("ppp"); LogOnIdentity id = key; IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Passphrase = new Passphrase("ppp"); e.IsAskingForPreviouslyUnknownPassphrase = true; return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(id); Assert.That(ivm.LogOnIdentity.Passphrase.Text, Is.EqualTo("ppp")); Assert.That(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint, Is.EqualTo(id.Passphrase.Thumbprint)); }
public async Task AskForLogOnPassphraseWithKnownIdentityButWrongPassphraseEntered() { Passphrase passphrase = new Passphrase("aaa"); Passphrase id = passphrase; Resolve.FileSystemState.KnownPassphrases.Add(id); IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Passphrase = new Passphrase("bbb"); return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(null); Assert.That(ivm.LogOnIdentity == LogOnIdentity.Empty); Assert.That(Resolve.FileSystemState.KnownPassphrases.Count(), Is.EqualTo(1)); }
public async Task <ServiceResult> RateDrink(IdentityViewModel viewModel, RateType rateType) { var result = await drinkService.GetSingle(viewModel); if (result.IsValid) { if (rateType == RateType.Like) { result.Data.Like++; } if (rateType == RateType.Unlike) { result.Data.Unlike++; } return(await drinkService.Update(result.Data)); } return(result); }
public async Task TestLogOnExistingIdentity() { Passphrase passphrase = new Passphrase("p"); Passphrase id = passphrase; Resolve.FileSystemState.KnownPassphrases.Add(id); IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Passphrase = new Passphrase("p"); return(Task.FromResult <object>(null)); }; await ivm.LogOnLogOff.ExecuteAsync(null); Assert.That(Resolve.KnownIdentities.IsLoggedOn); }
public async Task AskForNewLogOnPassphraseAutomaticallyBecauseNoIdentitiesExists() { Resolve.FileSystemState.KnownPassphrases.Add(Passphrase.Create("aaa")); IdentityViewModel ivm = new IdentityViewModel(Resolve.FileSystemState, Resolve.KnownIdentities, Resolve.UserSettings, Resolve.SessionNotify); ivm.LoggingOnAsync = (e) => { e.Passphrase = new Passphrase("aaa"); e.Name = "New User Passphrase"; return(Task.FromResult <object>(null)); }; await ivm.AskForLogOnPassphrase.ExecuteAsync(LogOnIdentity.Empty); Assert.That(ivm.LogOnIdentity.Passphrase.Text, Is.EqualTo("aaa")); Assert.That(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint, Is.EqualTo(new Passphrase("aaa").Thumbprint)); Passphrase id = Resolve.FileSystemState.KnownPassphrases.FirstOrDefault(i => i.Thumbprint == new Passphrase("aaa").Thumbprint); Assert.That(id.Thumbprint, Is.EqualTo(Resolve.KnownIdentities.DefaultEncryptionIdentity.Passphrase.Thumbprint)); }