示例#1
0
        public static ModelResult <T> CheckToken <T>(string token, BSDNContext context)
        {
            ModelResult <T> result;

            if (token == null)
            {
                result = new ModelResult <T>(405, default, "Need Token");
示例#2
0
        public static async Task CreateCommentNotice(Comment comment, BSDNContext context, int userId, string type)
        {
            if (userId == 0)
            {
                return;
            }
            Notice notice = new Notice(userId, $@"New {type}", $@"/api/article/{comment.ArticleId}");
            await context.Notices.AddAsync(notice);

            await context.SaveChangesAsync();
        }
示例#3
0
        public static async Task CreateFollowNotice(UserFollow userFollow, BSDNContext context)
        {
            User follower = await context.Users.FirstOrDefaultAsync(u => u.UserId == userFollow.FollowerId);

            User following = await context.Users.FirstOrDefaultAsync(u => u.UserId == userFollow.FollowingId);

            Notice notice = new Notice(following.UserId, $@"New Follower|{follower.Nickname}|{follower.UserId}", null);
            await context.AddAsync(notice);

            await context.SaveChangesAsync();
        }
示例#4
0
        public static string GenerateSessionToken(User user, BSDNContext context)
        {
            var rawToken      = user.Nickname + user.UserId + user.Email + DateTime.Now.ToString();
            var md5           = MD5.Create();
            var data          = md5.ComputeHash(Encoding.UTF8.GetBytes(rawToken));
            var stringBuilder = new StringBuilder();

            foreach (var ch in data)
            {
                stringBuilder.Append(ch.ToString("x2"));
            }

            string  token   = stringBuilder.ToString();
            Session session = context.Sessions.FirstOrDefault(s => s.SessionToken == token);

            return(session == null ? token : null);
        }
示例#5
0
        public static async Task CreateArticleNotice(Article article, BSDNContext context)
        {
            User userResult = await context.Users.FirstOrDefaultAsync(u => u.UserId == article.UserId);

            List <Notice> notices = await context.UserFollows
                                    .Where(uf => uf.FollowingId == userResult.UserId)
                                    .Select(uf => uf.FollowerId)
                                    .Select(uid => new Notice(uid, $@"New Article|{article.Title}|{article.ArticleId}",
                                                              $@"/api/article/{article.ArticleId}"))
                                    .ToListAsync();

            foreach (var notice in notices)
            {
                await context.Notices.AddAsync(notice);
            }

            await context.SaveChangesAsync();
        }
示例#6
0
 public ArticleTagController(BSDNContext context)
 {
     _context = context;
 }
示例#7
0
 public FollowController(BSDNContext context)
 {
     _context = context;
 }
示例#8
0
 public SessionController(BSDNContext context)
 {
     _context = context;
 }
 public CommentController(BSDNContext context)
 {
     _context = context;
 }
示例#10
0
 public TagController(BSDNContext context)
 {
     _context = context;
 }
示例#11
0
 public UserController(BSDNContext context)
 {
     _context = context;
 }
 public NoticeController(BSDNContext context)
 {
     _context = context;
 }
示例#13
0
 public FileController(BSDNContext context)
 {
     _context = context;
 }