Ejemplo n.º 1
0
        public async Task <ApiResultData <Profile> > GetProfile()
        {
            var result   = new ApiResultData <Profile>();
            var userInfo = await _userService.GetItemByUserIdAsync(HttpContext.User.GetUserId(), UserStatus.Normal);

            if (userInfo == null)
            {
                result.Code    = 400;
                result.Message = "获取用户信息失败";
                return(result);
            }
            var profile = new Profile
            {
                UserId      = userInfo.UserId,
                Username    = userInfo.Username,
                DisplayName = userInfo.DisplayName,
                AvatarUrl   = userInfo.AvatarUrl,
                LogoUrl     = userInfo.LogoUrl,
                Groups      = await _groupService.GetInfoPathAsync(userInfo.Group.GroupId),
                Role        = userInfo.Role,
            };

            result.Code    = 200;
            result.Message = "获取用户信息成功";
            result.Data    = profile;
            return(result);
        }
        public async Task <ApiResultData <ApiResultTokenData> > WeixinWebLogin(WeixinWebLoginInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var openId       = await _weixinUserService.GetWeixinWebOpenIdAsync(input.Code);

            if (openId == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "异常:获取微信 OpenId 失败";
                return(returnResult);
            }
            var userInfo = await _weixinUserService.GetOrGenerateItemByWeixinWebOpenIdAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                            _authenticationSettings.RegisterDefaultStatus,
                                                                                            openId);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "异常:微信小程序登录失败";
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "登录成功";
            return(returnResult);
        }
Ejemplo n.º 3
0
        public async Task <ApiResultData <ApiResultTokenData> > WeixinAppLoginWithMobile(WeixinAppLoginWithMobileInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var userInfo     = await _weixinUserService.GetOrGenerateItemByWeixinAppCodeAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                              _authenticationSettings.RegisterDefaultStatus,
                                                                                              input.Code,
                                                                                              input.EncryptedData,
                                                                                              input.IV);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "异常:微信小程序登录失败";
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            await SaveUserActionLogAsync(userInfo.UserId, 1, "微信小程序登录", input);

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "登录成功";
            return(returnResult);
        }
Ejemplo n.º 4
0
        public async Task <ApiResultData <Role> > AddRole(RoleInput roleInput)
        {
            var result = new ApiResultData <Role>();

            if (roleInput.RoleId.HasValue)
            {
                // Guid.Empty 也不允许
                result.Code    = 400;
                result.Message = "添加角色失败:无需提供参数 RoleId";
                return(result);
            }

            roleInput.RoleId = Guid.NewGuid();
            if (!await _roleService.SaveAsync(roleInput, ModelState))
            {
                result.Code    = 400;
                result.Message = "添加角色失败:" + ModelState.FirstErrorMessage();
                return(result);
            }

            // 角色名称不能重复
            var role = await _roleService.GetItemAsync(roleInput.Name);

            result.Code    = 200;
            result.Message = "添加角色成功";
            result.Data    = role;
            return(result);
        }
Ejemplo n.º 5
0
        public async Task <ApiResultData <Role> > EditRole(RoleInput roleInput)
        {
            var result = new ApiResultData <Role>();

            if (roleInput.RoleId.IsNullOrEmpty())
            {
                result.Code    = 400;
                result.Message = "编辑角色失败:必须提供参数 RoleId";
                return(result);
            }

            if (!await _roleService.SaveAsync(roleInput, ModelState))
            {
                result.Code    = 400;
                result.Message = "编辑角色失败:" + ModelState.FirstErrorMessage();
                return(result);
            }

            // 角色名称不能重复
            var role = await _roleService.GetItemAsync(roleInput.Name);

            result.Code    = 200;
            result.Message = "编辑角色成功";
            result.Data    = role;
            return(result);
        }
Ejemplo n.º 6
0
        public async Task <ApiResultData <ApiResultTokenData> > GetGuestToken(GuestInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var userInfo     = await _userService.GetOrGenerateItemByUniqueIdAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                   _authenticationSettings.RegisterDefaultStatus,
                                                                                   input.UniqueId);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "异常:根据唯一识别码获取用户失败";
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            await SaveUserActionLogAsync(userInfo.UserId, 1, "根据唯一识别码获取游客 Token", input);

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "根据唯一识别码获取游客 Token 成功";
            return(returnResult);
        }
Ejemplo n.º 7
0
        public async Task <ApiResultData <DataVersion> > GetDataVersion(DataVersionTypeIdInput dataVersionTypeIdInput)
        {
            var returnResult = new ApiResultData <DataVersion>();
            var item         = await _dataVersionService.GetGlobalAsync(dataVersionTypeIdInput.TypeId);

            returnResult.Data    = item;
            returnResult.Code    = 200;
            returnResult.Message = "获取成功";
            return(returnResult);
        }
Ejemplo n.º 8
0
        public async Task <ApiResultData <List <RegionTreeNode> > > GetRegionTree()
        {
            var returnResult = new ApiResultData <List <RegionTreeNode> >();
            var tree         = await _regionService.GetRegiontTreeAsync();

            returnResult.Data    = tree;
            returnResult.Code    = 200;
            returnResult.Message = "获取成功";
            return(returnResult);
        }
Ejemplo n.º 9
0
        public async Task <ApiResultData <List <RegionTreeNode> > > GetRegiontParentTreeByParentIdPath(ParentIdPathInput parentIdPath)
        {
            var returnResult = new ApiResultData <List <RegionTreeNode> >();
            var tree         = await _regionService.GetRegiontParentTreeAsync(parentIdPath.ParentIdPath);

            returnResult.Data    = tree;
            returnResult.Code    = 200;
            returnResult.Message = "获取成功";
            return(returnResult);
        }
Ejemplo n.º 10
0
        public async Task <ApiResultData <IEnumerable <DataVersion> > > GetDataVersionList()
        {
            var returnResult = new ApiResultData <IEnumerable <DataVersion> >();
            var list         = await _dataVersionService.GetAllAsync();

            returnResult.Data    = list;
            returnResult.Code    = 200;
            returnResult.Message = "获取成功";
            return(returnResult);
        }
Ejemplo n.º 11
0
        public async Task <ApiResultData <List <RegionInfo> > > GetRegionInfoList(ParentIdNullableInput parentIdInput)
        {
            var returnResult = new ApiResultData <List <RegionInfo> >();
            var list         = await _regionService.GetRegionInfoListAsync(parentIdInput.ParentId);

            returnResult.Data    = list;
            returnResult.Code    = 200;
            returnResult.Message = "获取成功";
            return(returnResult);
        }
Ejemplo n.º 12
0
        public async Task <ApiResultData <Page <UserInfo> > > GetUserPage(UserPageSearchCriteria criteria)
        {
            var result = new ApiResultData <Page <UserInfo> >();
            var page   = await _userService.GetPageAsync(criteria);

            result.Code    = 200;
            result.Message = "获取用户列表成功";
            result.Data    = page;

            return(result);
        }
Ejemplo n.º 13
0
        public async Task <ApiResultData <NotificationUser> > GetNewestNotification(int?currentNotificationId)
        {
            int userId = int.Parse(HttpContext.User.Identity.Name);
            var result = new ApiResultData <NotificationUser>
            {
                Code    = 200,
                Message = "获取最新消息成功",
                Data    = await _notificationService.GetNewestAsync(userId, currentNotificationId),
            };

            return(result);
        }
Ejemplo n.º 14
0
        public ApiResultData <IEnumerable <KeyValuePair <UserStatus, string> > > GetUserStatuList()
        {
            var list   = typeof(UserStatus).GetEnumDictionary <UserStatus>();
            var result = new ApiResultData <IEnumerable <KeyValuePair <UserStatus, string> > >
            {
                Code    = 200,
                Message = "获取用户状态列表成功",
                Data    = list,
            };

            return(result);
        }
        public async Task <ApiResultData <Page <NotificationUser> > > GetNotificationsForManager([FromBody] NotificationPageSearchCriteria criteria)
        {
            var page = await _notificationService.GetPageAsync(criteria);

            var result = new ApiResultData <Page <NotificationUser> >
            {
                Code    = 200,
                Message = "获取通知列表成功",
                Data    = page,
            };

            return(result);
        }
Ejemplo n.º 16
0
        public async Task <ApiResultData <List <PermissionTreeNode> > > GetPermissionTree()
        {
            var tree = await _permissionService.GetTreeInCacheAsync();

            var result = new ApiResultData <List <PermissionTreeNode> >
            {
                Code    = 200,
                Message = "获取权限树成功",
                Data    = tree,
            };

            return(result);
        }
Ejemplo n.º 17
0
        public async Task <ApiResultData <List <GroupTreeNode> > > GetGroupTree()
        {
            var tree = await _groupService.GetTreeInCacheAsync();

            var result = new ApiResultData <List <GroupTreeNode> >
            {
                Code    = 200,
                Message = "获取分组树成功",
                Data    = tree,
            };

            return(result);
        }
Ejemplo n.º 18
0
        public async Task <ApiResultData <List <RoleBase> > > GetRoleBaseList()
        {
            var roles = await _roleService.GetBaseListInCacheAsync();

            var result = new ApiResultData <List <RoleBase> >
            {
                Code    = 200,
                Message = "获取角色列表成功",
                Data    = roles,
            };

            return(result);
        }
Ejemplo n.º 19
0
        public async Task <ApiResultData <List <Group> > > GetGroupList()
        {
            var groups = await _groupService.GetListInCacheAsync();

            ProjectGroups(ref groups);
            var result = new ApiResultData <List <Group> >
            {
                Code    = 200,
                Message = "获取分组列表成功",
                Data    = groups,
            };

            return(result);
        }
Ejemplo n.º 20
0
        public async Task <ApiResultData <Page <NotificationUser> > > GetNotifications(NotificationPageSearchCriteria criteria)
        {
            criteria.ToUserId = HttpContext.User.GetUserId();
            var page = await _notificationService.GetPageAsync(criteria);

            var result = new ApiResultData <Page <NotificationUser> >
            {
                Code    = 200,
                Message = "获取通知列表成功",
                Data    = page,
            };

            return(result);
        }
Ejemplo n.º 21
0
        public async Task <ApiResultData <BulletinInput> > GetBulletin()
        {
            var bulletin = await _bulletinService.GetItemInCacheAsync();

            var bulletinInput = bulletin.MapTo <BulletinInput>();
            var result        = new ApiResultData <BulletinInput>
            {
                Code    = 200,
                Message = "获取系统公告成功",
                Data    = bulletinInput,
            };

            return(result);
        }
Ejemplo n.º 22
0
        public async Task <ApiResultData <ApiResultTokenData> > MobilePasswordLogin(MobilePasswordLoginInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var userInfo     = await _userService.GetNormalUserAsync(input.Mobile, input.Password);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = "手机号或密码错误,请重试。";
                return(returnResult);
            }

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "登录成功";
            return(returnResult);
        }
Ejemplo n.º 23
0
        public async Task <ApiResultData <ApiResultTokenData> > Login(AccountPasswordLoginInput input)
        {
            var result   = new ApiResultData <ApiResultTokenData>();
            var userInfo = await _userService.GetNormalUserAsync(input.Account, input.Password);

            if (userInfo == null)
            {
                result.Code    = 400;
                result.Message = "账号或密码错误,或用户状态不允许登录";
                return(result);
            }

            result.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            result.Code    = 200;
            result.Message = "登录成功";
            return(result);
        }
Ejemplo n.º 24
0
        public async Task <ApiResultData <ApiResultTokenData> > MobileLogin(MobileValidationCodeLoginInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var verifyMobileValidationCodeInput = new VerifyMobileValidationCodeInput
            {
                Mobile         = input.Mobile,
                Type           = MobileValidationCodeType.Login, // 登录
                ValidationCode = input.ValidationCode,
            };

            if (!await _mobileUserService.VerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }
            var userInfo = await _mobileUserService.GetOrGenerateItemByMobileAsync(_authenticationSettings.RegisterDefaultGroupId,
                                                                                   _authenticationSettings.RegisterDefaultStatus,
                                                                                   input.Mobile,
                                                                                   true,
                                                                                   ModelState);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            await SaveUserActionLogAsync(userInfo.UserId, 1, "手机号 + 验证码 登录", input);

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "登录成功";
            return(returnResult);
        }
Ejemplo n.º 25
0
        public async Task <ApiResultData <ApiResultTokenData> > MobilePassswordRegister(MobilePassswordValidationCodeRegisterInput input)
        {
            var returnResult = new ApiResultData <ApiResultTokenData>();
            var verifyMobileValidationCodeInput = new VerifyMobileValidationCodeInput
            {
                Mobile         = input.Mobile,
                Type           = MobileValidationCodeType.Register, // 注册
                ValidationCode = input.ValidationCode,
            };

            if (!await _mobileUserService.VerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput, ModelState))
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }
            await _mobileUserService.FinishVerifyMobileValidationCodeAsync(verifyMobileValidationCodeInput.Mobile, verifyMobileValidationCodeInput.Type, ModelState);

            var userInfo = await _mobileUserService.GenerateItemAsync(_authenticationSettings.RegisterDefaultGroupId, _authenticationSettings.RegisterDefaultStatus, input, ModelState);

            if (userInfo == null)
            {
                returnResult.Code    = 400;
                returnResult.Message = ModelState.FirstErrorMessage();
                return(returnResult);
            }

            if (userInfo.Status != UserStatus.Normal)
            {
                returnResult.Code    = 201;
                returnResult.Message = "注册成功,请等待审核。";
                return(returnResult);
            }

            returnResult.Data = await _tokenService.GenerateApiResultTokenData(userInfo);

            returnResult.Code    = 200;
            returnResult.Message = "注册成功";
            return(returnResult);
        }
Ejemplo n.º 26
0
        public ApiResultData <List <Menu> > GetMenus()
        {
            var list          = new List <Menu>();
            var menuProviders = _menuProviders.OrderBy(m => m.Order);

            foreach (var menuProvider in menuProviders)
            {
                var items = menuProvider.GetModuleMenus();
                foreach (var item in items)
                {
                    AddMenuToList(list, item);
                }
            }

            var result = new ApiResultData <List <Menu> >
            {
                Code    = 200,
                Message = "获取菜单成功",
                Data    = list
            };

            return(result);
        }
Ejemplo n.º 27
0
        public async Task <ApiResultData <MetaDataItem> > GetModuleMetaDatas()
        {
            var permissions = await _permissionService.GetListInCacheAsync();

            ProjectPermissions(ref permissions);

            var roles = await _roleService.GetListInCacheAsync();

            var groups = await _groupService.GetListInCacheAsync();

            var result = new ApiResultData <MetaDataItem>
            {
                Code    = 200,
                Message = "获取模块元数据成功",
                Data    = new MetaDataItem
                {
                    Permissions = permissions,
                    Roles       = roles,
                    Groups      = groups,
                },
            };

            return(result);
        }