Skip to content

Commit ef660ec

Browse files
authored
Merge pull request #4 from Qtoss-AI/hdongDev
hdong: Add modify Email,pone API.
2 parents 4515d49 + 439d222 commit ef660ec

File tree

5 files changed

+61
-0
lines changed

5 files changed

+61
-0
lines changed

src/Infrastructure/BotSharp.Abstraction/Repositories/IBotSharpRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ public interface IBotSharpRepository
2525
void UpdateUserVerified(string userId) => throw new NotImplementedException();
2626
void UpdateUserVerificationCode(string userId, string verficationCode) => throw new NotImplementedException();
2727
void UpdateUserPassword(string userId, string password) => throw new NotImplementedException();
28+
void UpdateUserEmail(string userId, string email)=> throw new NotImplementedException();
29+
void UpdateUserPhone(string userId, string Iphone) => throw new NotImplementedException();
2830
#endregion
2931

3032
#region Agent

src/Infrastructure/BotSharp.Abstraction/Users/IUserService.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@ public interface IUserService
1414
Task<bool> VerifyEmailExisting(string email);
1515
Task<bool> SendVerificationCodeResetPassword(User user);
1616
Task<bool> ResetUserPassword(User user);
17+
Task<bool> ModifyUserEmail(string email);
18+
Task<bool> ModifyUserPhone(string phone);
1719
}

src/Infrastructure/BotSharp.Core/Users/Services/UserService.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,33 @@ public async Task<bool> ResetUserPassword(User user)
364364
db.UpdateUserPassword(record.Id, newPassword);
365365
return true;
366366
}
367+
368+
public async Task<bool> ModifyUserEmail(string email)
369+
{
370+
var curUser = await GetMyProfile();
371+
var db = _services.GetRequiredService<IBotSharpRepository>();
372+
var record = db.GetUserById(curUser.Id);
373+
if (record == null)
374+
{
375+
return false;
376+
}
377+
378+
db.UpdateUserEmail(record.Id, email);
379+
return true;
380+
}
381+
382+
public async Task<bool> ModifyUserPhone(string phone)
383+
{
384+
var curUser = await GetMyProfile();
385+
var db = _services.GetRequiredService<IBotSharpRepository>();
386+
var record = db.GetUserById(curUser.Id);
387+
388+
if (record == null)
389+
{
390+
return false;
391+
}
392+
393+
db.UpdateUserPhone(record.Id, phone);
394+
return true;
395+
}
367396
}

src/Infrastructure/BotSharp.OpenAPI/Controllers/UserController.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,18 @@ public async Task<bool> ResetUserPassword([FromBody] UserResetPasswordModel user
121121
return await _userService.ResetUserPassword(user.ToUser());
122122
}
123123

124+
[HttpPost("/user/email/modify")]
125+
public async Task<bool> ModifyUserEmail([FromQuery] string email)
126+
{
127+
return await _userService.ModifyUserEmail(email);
128+
}
129+
130+
[HttpPost("/user/phone/modify")]
131+
public async Task<bool> ModifyUserPhone([FromQuery] string phone)
132+
{
133+
return await _userService.ModifyUserPhone(phone);
134+
}
135+
124136
#region Avatar
125137
[HttpPost("/user/avatar")]
126138
public bool UploadUserAvatar([FromBody] BotSharpFile file)

src/Plugins/BotSharp.Plugin.MongoStorage/Repository/MongoRepository.User.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,20 @@ public void UpdateUserPassword(string userId, string password)
7272
.Set(x => x.UpdatedTime, DateTime.UtcNow);
7373
_dc.Users.UpdateOne(filter, update);
7474
}
75+
76+
public void UpdateUserEmail(string userId, string email)
77+
{
78+
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, userId);
79+
var update = Builders<UserDocument>.Update.Set(x => x.Email, email)
80+
.Set(x => x.UpdatedTime, DateTime.UtcNow);
81+
_dc.Users.UpdateOne(filter, update);
82+
}
83+
84+
public void UpdateUserPhone(string userId, string phone)
85+
{
86+
var filter = Builders<UserDocument>.Filter.Eq(x => x.Id, userId);
87+
var update = Builders<UserDocument>.Update.Set(x => x.Phone, phone)
88+
.Set(x => x.UpdatedTime, DateTime.UtcNow);
89+
_dc.Users.UpdateOne(filter, update);
90+
}
7591
}

0 commit comments

Comments
 (0)