Пример #1
0
        public IHttpActionResult LoggingUser(string authCode = "")
        {
            if (string.IsNullOrEmpty(authCode))
            {
                return(BadRequest("AuthCode is invalid"));
            }

            var dingdingUserInfo = _ddTalkService.GetUserInfo(authCode);

            if (dingdingUserInfo.IsError)
            {
                return(BadRequest("Get UserInfo Error ,because " + dingdingUserInfo.ErrMsg));
            }

            var account = _accountUserService.GetAccountUserByDDUserId(dingdingUserInfo.Userid);

            if (account != null)
            {
                account.LastActivityDate = DateTime.Now;
                account.LastLoginDate    = DateTime.Now;
                account.LastIpAddress    = _webHelper.GetCurrentIpAddress();
                account.FirstTime        = false;
                _accountUserService.UpdateAccountUser(account);
            }
            else
            {
                account = new AccountUser
                {
                    FirstTime        = true,
                    Active           = true,
                    DDUserId         = dingdingUserInfo.Userid,
                    NickName         = dingdingUserInfo.Name,
                    LastActivityDate = DateTime.Now,
                    LastLoginDate    = DateTime.Now,
                    LastIpAddress    = _webHelper.GetCurrentIpAddress(),
                };
                _accountUserService.InsertAccountUser(account);
            }

            return(Ok("Guid:" + account.AccountUserGuid));
        }