public async Task UploadTemplate()
        {
            // 获取用户名
            var template = Body.ToObject <Template>();

            template.userId     = Token.UserId;
            template.createDate = DateTime.Now;

            LiteDb.Insert(template);
            await ResponseSuccessAsync(template);
        }
Пример #2
0
        public async Task UserLogin()
        {
            // 读取jsonData
            var body = JObject.Parse(await HttpContext.GetRequestBodyAsStringAsync());

            string userId   = body.SelectToken(Fields.userName).ValueOrDefault(string.Empty);
            string password = body.SelectToken(Fields.password).ValueOrDefault(string.Empty); // 由于是客户端,不加密

            // 判断数据正确性
            if (string.IsNullOrEmpty(userId))
            {
                await ResponseErrorAsync("用户名为空");
            }

            if (string.IsNullOrEmpty(password))
            {
                await ResponseErrorAsync("密码为空");

                return;
            }

            // 获取数据库
            var user = LiteDb.Query <User>().Where(u => u.userId == userId).FirstOrDefault();

            if (user == null)
            {
                // 新建用户
                LiteDb.Insert(new User()
                {
                    userId     = userId,
                    password   = password,
                    createDate = DateTime.Now
                });

                // 新建用户后,同时给用户建立默认配置
                LiteDb.Insert(Setting.DefaultSetting(userId));
            }
            else
            {
                // 判断密码正确性
                if (user.password != password)
                {
                    await ResponseErrorAsync("密码错误");

                    return;
                }
            }

            UserConfig uConfig  = IoC.Get <UserConfig>();
            JwtToken   jwtToken = new JwtToken(uConfig.TokenSecret, userId, JwtToken.DefaultExp());

            await ResponseSuccessAsync(new JObject(new JProperty(Fields.token, jwtToken.Token)));
        }
Пример #3
0
        public async Task NewGroup()
        {
            var parentId    = Body.Value <string>("parentId");
            var name        = Body.Value <string>("name");
            var groupType   = Body.Value <string>("groupType");
            var description = Body.Value <string>("description");

            var newGroup = new Group()
            {
                userId      = Token.UserId,
                parentId    = parentId,
                name        = name,
                groupType   = groupType,
                description = description,
            };

            LiteDb.Insert(newGroup);

            await ResponseSuccessAsync(newGroup);
        }
Пример #4
0
        public SomeViewModel()
        {
            AddPerson = new CoreCommand(async(obj) =>
            {
                var p = new Person()
                {
                    FirstName = this.FirstName,
                    LastName  = this.LastName,
                    DOB       = DateTime.Now
                };

                var result = await LiteDb.Insert <Person>(p);
                if (result.Success)
                {
                    People.Add(p);
                    FirstName = string.Empty;
                    LastName  = string.Empty;
                    await CoreSettings.AppNav.PopAsync();
                }
            });
        }