コード例 #1
0
ファイル: AuthController.cs プロジェクト: Se0ng11/ReactSupply
        public async Task <string> LoginAsync([FromBody] LoginViewModel model)
        {
            try
            {
                bool            isSuper = model.UserName == _setting.GetSuperId();
                ApplicationUser user    = await _userManager.FindByNameAsync(model.UserName);

                string token = "";

                if (user == null)
                {
                    token            = Tools.GenerateJwtToken(_setting, model.UserName, "", "", isSuper, out string outRefreshToken);
                    _responseMessage = await LoginResult(user, isSuper, token, outRefreshToken);
                }
                else
                {
                    var role = await _userManager.GetRolesAsync(user);

                    token            = Tools.GenerateJwtToken(_setting, model.UserName, role[0], "", isSuper, out string outRefreshToken);
                    _responseMessage = await LoginResult(user, isSuper, token, outRefreshToken);
                }
            }
            catch (Exception ex)
            {
                _responseMessage.Status = Status.MessageType.FAILED.ToString();
                _responseMessage.Result = ex.Message;
            }

            return(Tools.ConvertToJSON(_responseMessage));
        }
コード例 #2
0
        public async Task <string> GetMenu()
        {
            ApplicationUser user = await _userManager.FindByNameAsync(User.Identity.Name);

            var superId = _setting.GetSuperId();
            var obj     = new MenuLogic(_context);
            var obj1    = new SubMenuLogic(_context);

            string data = "";

            if (User.Identity.Name == superId)
            {
                data = await obj.SelectVisibleData();
            }
            else
            {
                var role = await _userManager.GetRolesAsync(user);

                data = obj.SelectVisibleData(role[0]);
            }

            var data1 = obj1.SelectVisibleData();

            var format = new { top = data, left = data1 };

            return(Tools.ConvertToJSON(format));
        }
コード例 #3
0
        public async Task <string> RefreshToken([FromBody] JwtTokenResponse token)
        {
            ApplicationUser user = await _userManager.FindByNameAsync(token.UserId);

            bool isSuper = token.UserId == _setting.GetSuperId();

            if (isSuper)
            {
                var newToken = Tools.GenerateJwtToken(_setting, token.UserId, token.Role, token.Refresh, isSuper, out string outRefreshToken);

                _responseMessage.Status = Status.MessageType.SUCCESS.ToString();
                _responseMessage.Result = newToken;
            }
            else
            {
                var currentRefresh = await _userManager.GetAuthenticationTokenAsync(user, Messages.COMPANYNAME, Messages.REFRESHTOKEN);

                if (token.Refresh == currentRefresh)
                {
                    var newToken = Tools.GenerateJwtToken(_setting, user.UserName, token.Role, currentRefresh, isSuper, out string outRefreshToken);

                    _responseMessage.Status = Status.MessageType.SUCCESS.ToString();
                    _responseMessage.Result = newToken;
                }
                else
                {
                    _responseMessage.Status = Status.MessageType.FAILED.ToString();
                    _responseMessage.Result = Messages.INVALIDTOKEN;
                }
            }


            return(Tools.ConvertToJSON(_responseMessage));
        }
コード例 #4
0
        public string GetUsers()
        {
            _tableFormatter = new TableFormatter();

            var superId = _setting.GetSuperId();

            try
            {
                var users = _userManager.Users
                            .Where(x => x.UserName != superId)
                            .Include(u => u.UserRoles)
                            .ThenInclude(ur => ur.Role)
                            .OrderBy(x => x.UserName)
                            .Select(x => new UserViewModel
                {
                    UserName  = x.UserName,
                    Email     = x.Email,
                    Role      = x.UserRoles.FirstOrDefault().Role.Name,
                    LockupEnd = x.LockoutEnd,
                    Locked    = (x.LockoutEnd == null)? false: true
                })
                            .ToList();

                UserLogic obj = new UserLogic(_context);

                var header = obj.SelectSchemaHeaderSync();

                _tableFormatter.Header = header;
                _tableFormatter.Body   = Tools.ConvertToJSON(users);
            }catch (Exception ex)
            {
                _logger.LogError(ex.Message);
            }


            return(Tools.ConvertToJSON(_tableFormatter));
        }
コード例 #5
0
        public async Task <string> GetSupplyRecord(RequestData modal)
        {
            var user = await _userManager.FindByNameAsync(User.Identity.Name);

            var isGuest = (User.Identity.Name == _setting.GetSuperId()) ? true : await _userManager.IsInRoleAsync(user, "Guest");

            var obj   = new ConfigurationMainLogic(_context);
            var obj1  = new SupplyRecordLogic(_context);
            var data  = obj.SelectHeader(Convert.ToInt32(modal.identifier), isGuest);
            var data1 = obj1.SelectMenuData(modal.identifier, modal.updated);

            await Task.WhenAll(data, data1);

            var result = new TableFormatter {
                Header = data.Result, Body = data1.Result
            };

            return(Tools.ConvertToJSON(result));
        }