public ActionResult UserLogin(Login model) { var vLogin = _userServices.Login(model.Name, model.Password); if (vLogin.IsLogin) { SetRemember(model); var client = Client.GetAddress(); _userServices.AddLogin(vLogin, client.Ipv4); vLogin.User.Updatetime = DateTime.UtcNow; var identityModel = new IdentityModel <User>() { LoginTime = DateTime.UtcNow, Model = vLogin.User }; BaseIdentity.SetIdentity <User>(vLogin.SessionId, identityModel); model.SessionId = vLogin.SessionId; model.IsLogin = true; } if (vLogin.LoginStats == LoginStats.NAME) { ViewBag.Message = "邮箱或手机号错误."; model.IsLogin = false; } else if (vLogin.LoginStats == LoginStats.PASSOWRD) { ViewBag.Message = "密码错误."; model.IsLogin = false; } return(View("Index", model)); }
private void SetUser(BaseIdentity identity) { if (!UserId.HasValue) { UserId = SafeTry.IgnoreException(() => identity?.Id); } }
/// <summary>创建武将</summary> private RoleItem CreateRoleItem(BaseRoleInfo baserole, tg_user user, BaseIdentity baseIdentity) { var role = new tg_role { role_id = baserole.id, role_identity = baseIdentity.id, base_captain = baserole.captain, base_force = baserole.force, base_brains = baserole.brains, base_charm = baserole.charm, base_govern = baserole.govern, power = baserole.power, att_life = baserole.life, user_id = user.id, role_state = (int)RoleStateType.IDLE, role_level = 1, }; return(new RoleItem() { Kind = role, LifeSkill = new tg_role_life_skill(), FightSkill = new List <tg_role_fight_skill>(), }); }
private void SetIdentityProperties(BaseIdentity identity) { if ((IdentityProperties?.Count ?? 0) == 0) { IdentityProperties = identity?.GetCustomLoggingProperties() ?? new Dictionary <string, string>(); } }
public override void OnAuthorization(HttpActionContext actionContext) { if (!Convert.ToBoolean(Config.GetValue("IsAuthentication"))) { base.OnAuthorization(actionContext); return; } if (!actionContext.Request.Headers.Contains(Config._authorizationHeadKey)) { CreateAuthorizationResponse(actionContext, "Unauthorized Access Attempt"); } else { var token = actionContext.Request.Headers.Authorization.ToString(); if (!token.StartsWith(Config._authorizationTarget)) { CreateAuthorizationResponse(actionContext, "Bearer token expected"); } else { token = token.Replace(Config._authorizationTarget + " ", ""); var user = BaseIdentity.GetIdentity <User>(token); if (user.IsNotNull()) { base.OnAuthorization(actionContext); } else { CreateAuthorizationResponse(actionContext, "User does not exist"); } } } }
public void StoreAndSaveThenUpdateNewDocumentInsideTransactionSucceedsUsingSession() { var input = GenerateEditable(); using (var documentStore = NewRemoteDocumentStore(runInMemory: false, requestedStorage: "voron")) using (var session = documentStore.OpenSession()) { if (documentStore.DatabaseCommands.GetStatistics().SupportsDtc == false) { return; } session.Advanced.UseOptimisticConcurrency = true; session.Advanced.AllowNonAuthoritativeInformation = false; using (var transaction = new TransactionScope()) { var studentIds = new List <string>(); var students = new List <Student>(); input.Students.ForEach(x => { var updatedStudent = new Student { Name = x.Name, Email = x.Email, Id = BaseIdentity <Student> .IdTemplate() }; session.Store(updatedStudent); session.SaveChanges(); updatedStudent.LastUpdatedBy = "bob"; studentIds.Add(updatedStudent.Id); students.Add(updatedStudent); }); var updatedCourse = new Course { Name = input.Course.Name, Students = studentIds, LastUpdatedBy = "bob" }; session.Store(updatedCourse); session.SaveChanges(); students.ForEach(x => { x.CourseId = updatedCourse.Id; }); Assert.DoesNotThrow(() => session.SaveChanges()); transaction.Complete(); } } }
public void GivenClaimsIdentityWithNameIdentifierClaim_WhenIFindUserKey_ThenGetNameIdentifierClaimValue() { string expected = "this is the user key"; BaseIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, expected)); string actual = EducationSecurityIdentity.FindUserKey(BaseIdentity); Assert.AreEqual(expected, actual); }
public ActionResult Index() { var user = BaseIdentity.GetUser <User>(); var userRole = _iRoleServices.GetUserRoleByUserId(user.Model.Id).FirstOrDefault(); var token = BaseIdentity.GetClientToken(); ViewBag.Token = token; ViewBag.User = user.Model; ViewBag.UserRole = userRole; return(View()); }
public ActionResult Login(string token, string action) { if (token.IsNotNullOrEmpty()) { BaseIdentity.SetClientToken(token); if (BaseIdentity.GetUser <User>().IsNotNull()) { Response.Redirect(action ?? "/DyncForm", true); } } return(Index()); }
public ActionResult IsAuthority() { if (BaseIdentity.GetUser <User>().IsNull()) { return new ContentResult() { Content = "error" } } ; return(new ContentResult() { Content = "success" }); }
public void ProcessRequest(HttpContext context) { var request = context.Request; var response = context.Response; if (request.HttpMethod.ToUpper() != "POST") { response.Write("不支持此请求方式!!!"); response.End(); return; } var url = request[_locationTarget]; var token = request[BaseIdentity._storageName]; BaseIdentity.SetClientToken(token); context.Response.Redirect(url); context.Response.End(); }
public override bool AuthorizeHubMethodInvocation(IHubIncomingInvokerContext hubIncomingInvokerContext, bool appliesToMethod) { var request = hubIncomingInvokerContext.Hub.Context.Request; IdentityModel <User> user = null; var uuid = string.Empty; if (request.Cookies.Keys.Contains(IdentityConstant._storageName)) { uuid = request.Cookies[IdentityConstant._storageName].Value; if (string.IsNullOrEmpty(uuid)) { return(false); } user = BaseIdentity.GetIdentityNoWebClient <User>(uuid); if (user == null) { return(false); } } else if (request.QueryString["token"] == IdentityConstant._messageToken && !string.IsNullOrEmpty(request.QueryString["uuid"])) { user = new IdentityModel <User>(); user.Model = request.QueryString["user"].DeserializeObject <User>(); uuid = request.QueryString["uuid"]; } user.Model.Uuid = uuid; var connectionId = hubIncomingInvokerContext.Hub.Context.ConnectionId; var customHubCallerContext = new CustomHubCallerContext(new ServerRequest(request.Environment), connectionId); customHubCallerContext.UserIdentity = user; hubIncomingInvokerContext.Hub.Context = customHubCallerContext; return(true); }
public virtual string ToJwt(BaseIdentity identity) { identity.Expires = DateTime.UtcNow.AddMinutes(ExpirationMinutes); return(identity.SerializeJson().Encrypt(Encryption)); }
public ActionResult Logout() { BaseIdentity.Remove(); return(Index()); }
protected override bool AuthorizeCore(HttpContextBase httpContext) { var user = BaseIdentity.GetUser <User>(); return(user.IsNotNull()); }
public void GivenClaimsIdentityHasClaim_WhenIGetIsAuthenticated_ThenReturnTrue() { BaseIdentity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "whatever")); Assert.IsTrue(Target.IsAuthenticated); }
public string Validator(string token) { return(BaseIdentity.GetIdentity <User>(token).SerializeObject()); }