public ActionResult Index(AuthenticationModel model, string mode) { //add global validation error ModelState.AddFormError("LoginModel", "<strong>This account has been suspended!</strong> <a href=\"#\" class=\"alert-link\">Contact us</a> for more details."); return View(model); }
public AuthenticatedModel Authenticate(AuthenticationModel authentication) { return(SingleOrDefault <AuthenticatedModel> ( user => user.Login.Equals(authentication.Login) && user.Password.Equals(authentication.Password) && user.Status == Status.Active )); }
public string Post([FromBody] AuthenticationModel credentials) { if (CheckUser(credentials.Username, credentials.Password, credentials.CompanyId)) { return(JwtManager.GenerateToken(credentials.Username, credentials.CompanyId)); } throw new HttpResponseException(HttpStatusCode.Unauthorized); }
public ActionResult BalanceSheet() { if (!AuthenticationModel.IsAllowed("View", Constant.MenuName.BalanceSheet, Constant.MenuGroupName.Report)) { return(Content(Constant.ErrorPage.PageViewNotAllowed)); } return(View()); }
public ActionResult Index() { if (!AuthenticationModel.IsAllowed("View", Core.Constants.Constant.MenuName.Account, Core.Constants.Constant.MenuGroupName.Report)) { return(Content("You are not allowed to View this Page.")); } return(View()); }
public ActionResult <AuthenticationModel> Authenticate([FromBody] AuthenticationModel model) { if (model == null) { return(BadRequest()); } _userService.Authenticate(model); return(model); }
public ActionResult Index() { if (!AuthenticationModel.IsAllowed("View", Core.Constants.Constant.MenuName.CashBank, Core.Constants.Constant.MenuGroupName.Master)) { return(Content(Core.Constants.Constant.ErrorPage.PageViewNotAllowed)); } return(View()); }
public IActionResult Index(AuthenticationModel model) { if (!ModelState.IsValid) { return(View(model)); } return(RedirectToAction(nameof(Success))); }
public void AuthenticationDomain_Authenticate_Exists() { var authenticationModel = new AuthenticationModel { Login = "******", Password = "******" }; var result = AuthenticationDomain.Authenticate(authenticationModel); Assert.IsNotNull(result); }
public static AuthenticationModel Login(string userName, string password) { DataTable dt = GetResponseTable("Select UserID,Password from User where userName="******"Failed"}; if(dt..Rows.Count > 0 ) details = new AuthenticationModel{ LoginStatus = "Success", UserName = userName, UserId = dt["UserID"].toString(); return details; }
public ActionResult Index() { if (!AuthenticationModel.IsAllowed("View", Core.Constants.Constant.MenuName.SalesOrder, Core.Constants.Constant.MenuGroupName.Transaction)) { return(Content(Core.Constants.Constant.ErrorPage.PageViewNotAllowed)); } return(View()); }
public ActionResult Index() { if (!AuthenticationModel.IsAllowed("View", Core.Constants.Constant.MenuName.FPUser, Core.Constants.Constant.MenuGroupName.Setting)) { return(Content(Core.Constants.Constant.ErrorPage.PageViewNotAllowed)); } return(View(this)); }
public ActionResult Login(AuthenticationModel entity) { // Ensure we have a valid viewModel to work with if (!ModelState.IsValid) { return(View("Form", entity)); } try { using (var db = new WebChatEntities()) { //Retrive Stored Encrypt Password From Database According To Username (one unique field) var userInfo = db.app_user.Where(s => s.username == entity.Login.Username.Trim().ToLower()).FirstOrDefault(); //Verify password bool isLogin; if (userInfo != null) { string encrypt_password = userInfo.encrypted_password; isLogin = BCrypt.Net.BCrypt.Verify(entity.Login.Password.Trim().ToLower(), encrypt_password); } else { isLogin = false; } if (isLogin) { //Login Success //For Set Authentication in Cookie (Remeber ME Option) SignInRemember(entity.Login.Username, entity.Login.IsRemember); //Set A Unique ID in session Session["UserID"] = userInfo.app_user_id; //Change status online to true var customer = db.customers.Find(userInfo.app_user_id); customer.status_online = true; db.SaveChanges(); //Redirect to Index return(RedirectToAction("Index", "WebChat")); } else { //Login Fail TempData["ErrorMSG"] = "Thông tin đăng nháºp không đúng"; return(View("Form", entity)); } } } catch { throw; } }
public dynamic Update(Employee model) { try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.PersonalInfo, Core.Constants.Constant.MenuGroupName.Setting)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Edit record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _employeeService.GetObjectById(model.Id); data.NIK = model.NIK; data.Name = model.Name; data.TitleInfoId = model.TitleInfoId; data.DivisionId = model.DivisionId; data.PlaceOfBirth = model.PlaceOfBirth; data.BirthDate = model.BirthDate; data.Address = model.Address; data.PhoneNumber = model.PhoneNumber; data.Email = model.Email; data.Sex = model.Sex; data.MaritalStatus = model.MaritalStatus; data.Children = model.Children; data.Religion = model.Religion; data.NPWP = model.NPWP; data.NPWPDate = model.NPWPDate; data.JamsostekNo = model.JamsostekNo; data.WorkingStatus = model.WorkingStatus; data.StartWorkingDate = model.StartWorkingDate; data.AppointmentDate = model.AppointmentDate; data.ActiveStatus = model.ActiveStatus; data.NonActiveDate = model.NonActiveDate; model = _employeeService.UpdateObject(data, _divisionService, _titleInfoService); } catch (Exception ex) { LOG.Error("Update Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors })); }
public async Task <IActionResult> Authenticate(AuthenticationModel model) { var user = await Task.FromResult(_UserInfoService.Autenticate(model.Email, model.Password)).ConfigureAwait(false); if (user == null) { return(Unauthorized()); } return(Ok(user)); }
public void TestMethod1() { string userData = "4787299|1078|0|51dab274-5d73-4f56-8df9-da97d20cdc5b|1"; string connectionString = "Application Name=App;Data Source=dev-sql.corp.teamsupport.com; Initial Catalog=TeamSupportNightly;Persist Security Info=True;User ID=Dev-Sql-WebApp;Password=TeamSupportDev;Connect Timeout=500;"; AuthenticationModel authentication = AuthenticationModel.AuthenticationModelTest(userData, connectionString); using (ConnectionContext connection = new ConnectionContext(authentication)) { } }
public ActionResult ResetPassword(String hash, int userID) { if (hash.Length != 32 || !AuthenticationModel.VerifyUserHash(hash)) { ViewBag.ErrorMessage = ErrorMessage.INVALID_ACCESS; return(View()); } return(View()); }
// GET: Staff/Delete/5 public ActionResult Delete(int id) { USER user = AuthenticationModel.FindUser(id); AuthenticationModel.DeleteUser(id); EmailNotification.AccountDeletedNotification(user); return(RedirectToAction("index")); }
private void GoToInitialPage() { PageIndex = (int)Page.Initial; AuthenticationModel?.Dispose(); AuthenticationModel = null; WorkspaceModel?.Dispose(); WorkspaceModel = null; }
public IActionResult Login(AuthenticationModel model) { var response = _tideAuthentication.Login(AttachLogInformation(model)); if (response.Success) { return(Ok(response)); } return(BadRequest(response)); }
public async Task <IActionResult> AuthenticationForm(AuthenticationModel authenticationResponse) { if (ModelState.IsValid) { await Authenticate(authenticationResponse.Login); return(RedirectToAction("MyNotes", "NoteLibrary", new { area = "" })); } return(View()); }
//home page of the application, uses authentication public IActionResult Index() { UserModel user = AuthenticationModel.GetSessionUser(HttpContext.Session.Id); ViewBag.Username = user.UserName; ViewBag.Role = user.Role.RoleName; ViewBag.SignedIn = AuthenticationModel.GetSessionUser(HttpContext.Session.Id).RoleID != 3; return(View()); }
public IActionResult Authenticate([FromBody] AuthenticationModel model) { var user = _userRepo.Authenticate(model.Username, model.Password); if (user == null) { return(BadRequest(new { message = "Username or password is incorrect" })); } return(Ok(user)); }
public override bool Equals(object obj) { return(obj is DeviceIdentity identity && GetHashCode() == identity.GetHashCode() && Equals(IotHubConnectionString.DeviceId, identity.IotHubConnectionString.DeviceId) && Equals(IotHubConnectionString.HostName, identity.IotHubConnectionString.HostName) && Equals(IotHubConnectionString.ModuleId, identity.IotHubConnectionString.ModuleId) && Equals(AmqpTransportSettings.GetTransportType(), identity.AmqpTransportSettings.GetTransportType()) && Equals(AuthenticationModel.GetHashCode(), identity.AuthenticationModel.GetHashCode())); }
// GET: Profile public ActionResult EditProfile() { if (loginSession.AuthenticatedUser() == null) { return(RedirectToAction("Login", "Authentication")); } USER user = AuthenticationModel.FindUser(loginSession.AuthenticatedUser().USERID); return(View(user)); }
public async Task <AuthenticationModel> GetTokenAsync(TokenRequestModel model) { var authenticationModel = new AuthenticationModel(); var user = await _userManager.FindByEmailAsync(model.Email); if (user == null) { authenticationModel.IsAuthenticated = false; authenticationModel.Message = $"No Accounts Registered with {model.Email}."; return(authenticationModel); } if (await _userManager.CheckPasswordAsync(user, model.Password)) { if (user.EmailConfirmed) { authenticationModel.IsAuthenticated = true; var jwtSecurityToken = await CreateJwtToken(user); authenticationModel.Token = new JwtSecurityTokenHandler().WriteToken(jwtSecurityToken); authenticationModel.Email = user.Email; authenticationModel.UserName = user.UserName; var rolesList = await _userManager.GetRolesAsync(user).ConfigureAwait(false); authenticationModel.Roles = rolesList.ToList(); if (user.RefreshTokens.Any(a => a.IsActive)) { var activeRefreshToken = user.RefreshTokens.FirstOrDefault(a => a.IsActive); if (activeRefreshToken == null) { return(authenticationModel); } authenticationModel.RefreshToken = activeRefreshToken.Token; authenticationModel.RefreshTokenExpiration = activeRefreshToken.Expires; } else { var refreshToken = CreateRefreshToken(); authenticationModel.RefreshToken = refreshToken.Token; authenticationModel.RefreshTokenExpiration = refreshToken.Expires; user.RefreshTokens.Add(refreshToken); _context.Update(user); await _context.SaveChangesAsync(); } return(authenticationModel); } authenticationModel.Message = $"Email {user.Email} not verified ."; return(authenticationModel); } authenticationModel.IsAuthenticated = false; authenticationModel.Message = $"Incorrect Credentials for user {user.Email}."; return(authenticationModel); }
public dynamic UpdateDetail(CashSalesInvoiceDetail model) { decimal total = 0; try { if (!AuthenticationModel.IsAllowed("Edit", Core.Constants.Constant.MenuName.CashSalesInvoice, Core.Constants.Constant.MenuGroupName.Transaction)) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Edit record"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } if ((model.IsManualPriceAssignment || model.Discount > 0) && (!AuthenticationModel.IsAllowed("ManualPricing", Core.Constants.Constant.MenuName.CashSalesInvoice, Core.Constants.Constant.MenuGroupName.Transaction))) { Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "You are Not Allowed to Use Manual Pricing/Discount"); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } var data = _cashSalesInvoiceDetailService.GetObjectById(model.Id); data.ItemId = model.ItemId; data.Quantity = model.Quantity; data.Discount = model.Discount; data.IsManualPriceAssignment = model.IsManualPriceAssignment; data.AssignedPrice = model.AssignedPrice; data.CashSalesInvoiceId = model.CashSalesInvoiceId; model = _cashSalesInvoiceDetailService.UpdateObject(data, _cashSalesInvoiceService, _itemService, _warehouseItemService, _quantityPricingService); total = _cashSalesInvoiceService.GetObjectById(model.CashSalesInvoiceId).Total; } catch (Exception ex) { LOG.Error("Update Failed", ex); Dictionary <string, string> Errors = new Dictionary <string, string>(); Errors.Add("Generic", "Error " + ex); return(Json(new { Errors }, JsonRequestBehavior.AllowGet)); } return(Json(new { model.Errors, Total = total })); }
/// <summary> /// handles the authentication of the user and creates the authentication token /// </summary> /// <returns>nothing</returns> /// <remarks> /// jwames - 8/12/2014 - original code /// </remarks> public override async Task GrantResourceOwnerCredentials(OAuthGrantResourceOwnerCredentialsContext context) { context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" }); if (!ValidateApiKey(context)) { return; } string errMsg = null; // determine if we are authenticating an internal or external user if (ProfileHelper.IsInternalAddress(context.UserName)) { IUserDomainRepository ADRepo = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IUserDomainRepository)) as IUserDomainRepository; bool success = await Task.Run <bool>(() => ADRepo.AuthenticateUser(context.UserName, context.Password, out errMsg)); if (!success) { context.SetError("invalid_grant", errMsg); return; } } else { ICustomerDomainRepository ADRepo = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(ICustomerDomainRepository)) as ICustomerDomainRepository; AuthenticationModel authentication = await Task.Run <AuthenticationModel>(() => ADRepo.AuthenticateUser(context.UserName, context.Password)); if (!authentication.Status.Equals(AuthenticationStatus.Successful) && !authentication.Status.Equals(AuthenticationStatus.PasswordExpired)) { context.SetError("invalid_grant", authentication.Message); return; } } IUserProfileLogic _profileLogic = GlobalConfiguration.Configuration.DependencyResolver.GetService(typeof(IUserProfileLogic)) as IUserProfileLogic; UserProfileReturn userReturn = await Task.Run <UserProfileReturn>(() => _profileLogic.GetUserProfile(context.UserName)); if (userReturn.UserProfiles.Count == 0) { context.SetError("invalid_grant", "User profile does not exist in Commerce Server"); } else { _profileLogic.SetUserProfileLastLogin(userReturn.UserProfiles[0].UserId); var identity = new ClaimsIdentity(context.Options.AuthenticationType); identity.AddClaim(new Claim(ClaimTypes.Name, context.UserName)); identity.AddClaim(new Claim("name", context.UserName)); identity.AddClaim(new Claim("role", userReturn.UserProfiles[0].RoleName)); context.Validated(identity); } }
public async Task <ActionResult <TokenModel> > Authenticate([FromBody] AuthenticationModel model) { var tokenModel = await authenticationService.GetToken(model.Email, model.Password); if (tokenModel == null) { return(BadRequest(AuthenticationMessage.WrongUsernameOrPassword)); } return(tokenModel); }
public async Task <IActionResult> Authenticate([FromBody] AuthenticationModel auth) { var result = await _studentService.Authenticate(auth); if (result == null) { return(BadRequest(new { error = "Unable to authenticate" })); } return(Ok(result)); }
public AuthenticatedModel Authenticate(AuthenticationModel authentication) { new AuthenticationValidation().ValidateThrowException(authentication); authentication.Login = Hash.Generate(authentication.Login); authentication.Password = Hash.Generate(authentication.Password); var authenticated = DatabaseUnitOfWork.UserRepository.Authenticate(authentication); new AuthenticatedValidation().ValidateThrowException(authenticated); SaveUserLog(authenticated.UserId, LogType.Login); return(authenticated); }
public BsJsonResult Register(AuthenticationModel model) { //keep errors only for RegisterModel ModelState.ClearModelState(model.GetPropertyName(m => m.RegisterModel) + "."); //add validation error to BsRange field if (model.RegisterModel != null && model.RegisterModel.Interval != null && //model.RegisterModel.Interval.To.ItemValue.HasValue && //model.RegisterModel.Interval.From.ItemValue.HasValue && model.RegisterModel.Interval.From.ItemValue > model.RegisterModel.Interval.To.ItemValue) { ModelState.AddFieldError("RegisterModel.Interval", model.RegisterModel.Interval.GetType(), "Invalid interval"); } //if (model.RegisterModel != null && // model.RegisterModel.Interval != null && // model.RegisterModel.Interval.To.ItemValue.HasValue && // model.RegisterModel.Interval.From.ItemValue.HasValue && // model.RegisterModel.Interval.From.ItemValue.Value > model.RegisterModel.Interval.To.ItemValue.Value) //{ // ModelState.AddFieldError("RegisterModel.Interval", // model.RegisterModel.Interval.GetType(), // "Invalid interval"); //} //add validation error to BsSelectList field ModelState.AddFieldError("RegisterModel.CountriesList", model.RegisterModel.CountriesList.GetType(), "Selected location doesn't match your GPS location"); //add global validation error ModelState.AddFormError("RegisterModel", "This email address is in use."); if (ModelState.IsValid) { } else { //JSON serialize ModelState errors return new BsJsonResult( new Dictionary<string, object> { { "Errors", ModelState.GetErrors() } }, BsResponseStatus.ValidationError); } return new BsJsonResult(); }
public ActionResult Index(string mode) { var model = new AuthenticationModel() { LoginModel = new LoginModel(), RegisterModel = InitRegisterModel() }; if (!string.IsNullOrEmpty(mode)) if (mode.ToLower() == "login") { model.RegisterModel = null; } else if (mode.ToLower() == "register") { model.LoginModel = null; } RequireJsOptions.Add("registerUrl", Url.Action("Register")); return View(model); }