Ejemplo n.º 1
0
        public async Task <LoginViewResult> Login(JObject parameters)
        {
            var result   = new LoginViewResult();
            var username = parameters["Username"].ToString();
            var pwd      = parameters["Pwd"].ToString();

            var user = _userBusiness.GetUserByName("admin");

            if (user != null && user.Password == pwd)
            {
                var identity = new ClaimsIdentity(Startup.OAuthBearerOptions.AuthenticationType);

                var permissions = await _permissionBusiness.GetUserPermissions(1);

                //role
                foreach (var userRole in user.UserRoles)
                {
                    var roleName = userRole.Role.Name;
                    identity.AddClaim(new Claim(ClaimTypes.Role, roleName, ClaimValueTypes.String));
                }

                var ticket = new AuthenticationTicket(identity, CreateProperties(username));
                ticket.Properties.IssuedUtc  = DateTime.UtcNow;
                ticket.Properties.ExpiresUtc = DateTime.UtcNow.Add(TimeSpan.FromDays(1));

                var token = Startup.OAuthBearerOptions.AccessTokenFormat.Protect(ticket);
                result.Token       = token;
                result.Permissions = permissions.ToList();
                result.Status      = 0;
            }
            return(result);
        }
        public async Task <MulitViewResult <PermissionModel> > GetUserPermissions(int userId)
        {
            var result = new MulitViewResult <PermissionModel>();
            var data   = await _permissionBusiness.GetUserPermissions(userId);

            result.Datas    = data.ToList();
            result.AllCount = data.Count();
            return(result);
        }