public IActionResult Login(string uuid, [FromBody] JObject fromValue)
        {
            long logId = 0;

            try
            {
                int systemId = SystemID;
                logId = BaseApiManager.SaveLogs(uuid, fromValue);
                if (!IsUuid(uuid))
                {
                    return(Error(logId, "verify uuid fail!"));
                }
                bool   isParams  = IsLoginParams(fromValue);
                var    entity    = GetInterfaceAccountByUuid(uuid);
                string companyId = entity.CompanyID;
                string account   = GetJObjectValue(fromValue, "account");
                string password  = GetJObjectValue(fromValue, "password");
                var    result    = AccountService.VerifyAccountLoginPro(systemId, companyId, account, AlgorithmHelper.MD5(password));
                if (result)
                {
                    var    entityMember    = AccountService.GetAccountByUserName(systemId, companyId, account);
                    string memberId        = entityMember.MemberID;
                    var    tokenService    = new Common.Token.TokenHelper();
                    string token           = tokenService.GetToken();
                    string refreshToken    = tokenService.GetToken();
                    int    expiresIn       = AccessTokenExpiresIn;
                    string ipAddress       = Net.Ip;
                    int    createTimestamp = TimeHelper.GetUnixTimestamp();
                    var    createResult    = AccessTokenService.SaveAccessTokenPro(token, refreshToken, systemId, companyId, memberId, uuid, expiresIn, RefreshTokenExpiresIn, ipAddress, createTimestamp);
                    if (createResult)
                    {
                        return(Result(logId, new
                        {
                            access_token = token,
                            expiresin = expiresIn,
                            refresh_token = refreshToken,
                            memberid = memberId,
                            scope = "scope"
                        }));
                    }
                    return(Error(logId, "fail"));
                }
                return(Error(logId, "login fail!"));
            }
            catch (Exception ex)
            {
                return(Error(logId, ex.Message));
            }
        }
Example #2
0
        public IActionResult RefreshToken(string uuid, [FromBody] JObject fromValue)
        {
            long logId = 0;

            try
            {
                logId = BaseApiManager.SaveLogs(uuid);
                if (!IsUuid(uuid))
                {
                    return(Error(logId, "verify uuid fail!"));
                }
                bool   isParams      = IsLoginParams(fromValue);
                string fRefreshToken = GetJObjectValue(fromValue, "refresh_token");
                if (string.IsNullOrWhiteSpace(fRefreshToken))
                {
                    return(Error(logId, "refresh token not empty!"));
                }
                var    tokenService          = new Common.Token.TokenHelper();
                string token                 = tokenService.GetToken();
                string refreshToken          = tokenService.GetToken();
                int    expiresIn             = AccessTokenExpiresIn;
                int    refreshTokenExpiresIn = RefreshTokenExpiresIn;
                string ipAddress             = Net.Ip;
                int    createTimestamp       = TimeHelper.GetUnixTimestamp();
                var    createResult          = AccessTokenService.SaveRefreshTokenPro(fRefreshToken, token, refreshToken, expiresIn, refreshTokenExpiresIn, ipAddress, createTimestamp);
                if (createResult)
                {
                    var entityMember = AccessTokenService.GetAccessToken(token);
                    return(Result(new
                    {
                        access_token = token,
                        expiresin = expiresIn,
                        refresh_token = refreshToken,
                        memberid = entityMember.MemberID,
                        scope = "scope"
                    }));
                }
                return(Error(logId, "fail"));
            }
            catch (Exception ex)
            {
                return(Error(logId, ex.Message));
            }
        }