diff options
author | crupest <crupest@outlook.com> | 2019-04-22 17:15:06 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-22 17:15:06 +0800 |
commit | c288638f3805ef3d8028c75cb248f641a91c835d (patch) | |
tree | df8ffa6162d41c748b14c44a76c4859eca529fee /Timeline/Services/UserService.cs | |
parent | 6a73b71e4af6aa30cf6fca301d954bc01927a8c9 (diff) | |
download | timeline-c288638f3805ef3d8028c75cb248f641a91c835d.tar.gz timeline-c288638f3805ef3d8028c75cb248f641a91c835d.tar.bz2 timeline-c288638f3805ef3d8028c75cb248f641a91c835d.zip |
Fix a bug in cos service. Add avatar api.
Diffstat (limited to 'Timeline/Services/UserService.cs')
-rw-r--r-- | Timeline/Services/UserService.cs | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Timeline/Services/UserService.cs b/Timeline/Services/UserService.cs index 75ad3331..a444d434 100644 --- a/Timeline/Services/UserService.cs +++ b/Timeline/Services/UserService.cs @@ -140,6 +140,8 @@ namespace Timeline.Services /// <see cref="ChangePasswordResult.NotExists"/> if user does not exist. /// <see cref="ChangePasswordResult.BadOldPassword"/> if old password is wrong.</returns> Task<ChangePasswordResult> ChangePassword(string username, string oldPassword, string newPassword); + + Task<string> GetAvatarUrl(string username); } public class UserService : IUserService @@ -148,13 +150,15 @@ namespace Timeline.Services private readonly DatabaseContext _databaseContext; private readonly IJwtService _jwtService; private readonly IPasswordService _passwordService; + private readonly ITencentCloudCosService _cosService; - public UserService(ILogger<UserService> logger, DatabaseContext databaseContext, IJwtService jwtService, IPasswordService passwordService) + public UserService(ILogger<UserService> logger, DatabaseContext databaseContext, IJwtService jwtService, IPasswordService passwordService, ITencentCloudCosService cosService) { _logger = logger; _databaseContext = databaseContext; _jwtService = jwtService; _passwordService = passwordService; + _cosService = cosService; } public async Task<CreateTokenResult> CreateToken(string username, string password) @@ -294,5 +298,14 @@ namespace Timeline.Services await _databaseContext.SaveChangesAsync(); return ChangePasswordResult.Success; } + + public async Task<string> GetAvatarUrl(string username) + { + var exists = await _cosService.Exists("avatar", username); + if (exists) + return _cosService.GetObjectUrl("avatar", username); + else + return _cosService.GetObjectUrl("avatar", "__default"); + } } } |