public AuthResult Login(LoginModel model) { if (model == null) { throw new ArgumentNullException("model"); } var userId = _credentialsChecker.CheckUserExist(model.Nick, model.Password); if (userId.HasValue) { var token = _accessTokenGenerator.GenerateToken(userId.Value, model.Nick); var blogUser = _blogUserRepository.GetById(userId.Value); return(new AuthResult { Token = token, Message = "Ok", User = blogUser }); } return(new AuthResult { Message = "Unauthorized!" }); }
public GetBlogPostResponse GetBlogPost(GetBlogPostRequest request) { var response = new GetBlogPostResponse(); try { response.Post = _blogPostRepo.GetById(request.PostId); response.User = _blogUserRepo.GetById(response.Post.AuthorId); response.User.Permissions = null; response.RequestSuccessful = true; } catch (Exception) { response.RequestSuccessful = false; } return(response); }
public BlogUser Register(BlogUser user) { var id = _blogUserRepository.Insert(user); return(_blogUserRepository.GetById(id)); }