Esempio n. 1
0
        public ActionResult Login(SysUsrMstrQuery query)
        {
            try
            {
                var result = _sysUsrMstrService.Login(query);
                if (!result.IsSuccess)
                {
                    return(Fail(result.msg));
                }

                return(Success(result.msg, result.result));
            }
            catch (Exception ex)
            {
                return(Fail(ex.Message));
            }
        }
        public async Task ValidateAsync(ExtensionGrantValidationContext context)
        {
            var           userName = context.Request.Raw["username"];
            var           password = "";
            var           scope    = "";
            SysUsrMstrDto dto      = null;
            var           bizType  = context.Request.Raw["bizType"];
            var           orgNo    = context.Request.Raw["orgNo"];
            var           bgNo     = context.Request.Raw["bgNo"];

            if (string.IsNullOrEmpty(bizType) || string.IsNullOrEmpty(orgNo) || string.IsNullOrEmpty(bgNo))
            {
                context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid user credential");
            }
            else
            {
                dto = await _sysUsrMstrService.Login(userName, password, orgNo, bgNo, bizType);

                if (dto != null)
                {
                    var result = await _sysRoleMstrRepository.GetUserRoleScope(dto.Id);

                    if (result.Count != 0)
                    {
                        scope = result[0];
                    }

                    context.Result = new GrantValidationResult(
                        subject: userName,
                        authenticationMethod: "user",
                        claims: GetUserCliams(dto, scope)
                        );
                }
                else
                {
                    context.Result = new GrantValidationResult(TokenRequestErrors.InvalidGrant, "invalid user credential");
                }
            }
        }