#195 kicking out users api
This commit is contained in:
parent
b538a4ff92
commit
cbf4883a63
@ -8,8 +8,8 @@
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"GoogleAnalyticsCode": "",
|
||||
"APIRoot": "https://ganjgah.ir",
|
||||
"GlobalAPIRoot": "https://ganjgah.ir",
|
||||
"APIRoot": "http://localhost:3439",
|
||||
"GlobalAPIRoot": "http://localhost:3439",
|
||||
"SiteUrl": "http://localhost:33081",
|
||||
"ReadOnlyMode": "False"
|
||||
}
|
||||
|
||||
@ -59,7 +59,14 @@ namespace RMuseum.Services.Implementation
|
||||
/// <param name="secretCode"></param>
|
||||
public override string GetEmailSubject(RVerifyQueueType op, string secretCode)
|
||||
{
|
||||
string opString = op == RVerifyQueueType.SignUp ? "ثبت نام" : op == RVerifyQueueType.ForgotPassword ? "بازیابی کلمهٔ عبور" : "حذف حساب کاربری";
|
||||
string opString =
|
||||
op == RVerifyQueueType.SignUp ? "ثبت نام"
|
||||
:
|
||||
op == RVerifyQueueType.ForgotPassword
|
||||
?
|
||||
"بازیابی کلمهٔ عبور"
|
||||
:
|
||||
"حذف حساب کاربری";
|
||||
return $"{secretCode} کد {opString} شما در گنجور";
|
||||
}
|
||||
|
||||
@ -77,7 +84,10 @@ namespace RMuseum.Services.Implementation
|
||||
: op == RVerifyQueueType.ForgotPassword ?
|
||||
"اگر در گنجور فراموشی گذرواژه را نزدهاید یا گذرواژهتان را به خاطر آوردید لطفاً این نامه را نادیده بگیرید."
|
||||
:
|
||||
"اگر در گنجور حذف حساب کاربری را نزدهاید یا از حذف حساب کاربریتان منصرف شدهاید لطفاً این نامه را نادیده بگیرید.";
|
||||
op == RVerifyQueueType.UserSelfDelete ?
|
||||
"اگر در گنجور حذف حساب کاربری را نزدهاید یا از حذف حساب کاربریتان منصرف شدهاید لطفاً این نامه را نادیده بگیرید."
|
||||
:
|
||||
"";
|
||||
string content =
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"
|
||||
+
|
||||
@ -87,7 +97,7 @@ namespace RMuseum.Services.Implementation
|
||||
+
|
||||
"<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />"
|
||||
+
|
||||
$"<title>کد {opString} شما در گنجور: {secretCode}</title>"
|
||||
(op == RVerifyQueueType.KickOutUser ? $"<title>حذف حساب کاربری شما در گنجور</title>" : $" <title>کد {opString} شما در گنجور: {secretCode}</title>")
|
||||
+
|
||||
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>"
|
||||
+
|
||||
@ -110,6 +120,9 @@ namespace RMuseum.Services.Implementation
|
||||
"<tr><td>"
|
||||
+
|
||||
(
|
||||
op == RVerifyQueueType.KickOutUser ?
|
||||
$"<p style=\"font:normal 12px tahoma;direction:rtl\">کاربر گرامی، متأسفیم که به اطلاع برسانیم که به دلیل نقض قوانین استفاده از گنجور و به طور مشخص {secretCode} حساب کاربری شما به همراه حاشیهها، خوانشها و سایر اطلاعات خصوصیتان از گنجور حذف شده است. امیدواریم در آینده در صورت تمایل به استفاده از گنجور در چارچوبهای قابل پذیرش برای ما با حساب کاربری جدیدی پذیرای شما باشیم. با این ایمیل امکان ثبت نام مجدد نخواهید داشت./p>"
|
||||
:
|
||||
string.IsNullOrEmpty(signupCallbackUrl) ?
|
||||
$"<p style=\"font:normal 12px tahoma;direction:rtl\">لطفاً جهت تکمیل {opString} در گنجور کد <strong>{secretCode}</strong> را به عنوان رمز دریافتی در صفحهٔ {opString} وارد کنید.</p>"
|
||||
:
|
||||
|
||||
@ -943,6 +943,10 @@ namespace RSecurityBackend.Controllers
|
||||
if (!captchaRes.Result)
|
||||
return BadRequest("مقدار تصویر امنیتی درست وارد نشده است.");
|
||||
|
||||
var bannedEmail = await _appUserService.GetBannedEmailInformationAsync(signUpViewModel.Email);
|
||||
if (bannedEmail.Result != null)
|
||||
return BadRequest("ایمیل شما در لیست سیاه قرار دارد و نمیتوانید با آن مجدداً ثبت نام کنید.");
|
||||
|
||||
string clientIPAddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
|
||||
RServiceResult<RVerifyQueueItem> res = await _appUserService.SignUp(signUpViewModel.Email, clientIPAddress, signUpViewModel.ClientAppName, signUpViewModel.Language);
|
||||
if (res.Result == null)
|
||||
@ -1107,23 +1111,63 @@ namespace RSecurityBackend.Controllers
|
||||
/// <summary>
|
||||
/// log user bad behaviuor
|
||||
/// </summary>
|
||||
/// <param name="userId"></param>
|
||||
/// <param name="description"></param>
|
||||
/// <param name="userCause"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Authorize(Policy = SecurableItem.UserEntityShortName + ":" + SecurableItem.Administer)]
|
||||
[Route("behaviour/log/{userId}")]
|
||||
[Route("behaviour/log")]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(RUserBehaviourLog))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> LogUserBehaviourAsync(Guid userId, string description)
|
||||
public async Task<IActionResult> LogUserBehaviourAsync([FromBody] UserCauseViewModel userCause)
|
||||
{
|
||||
RServiceResult<RUserBehaviourLog> result = await _appUserService.LogUserBehaviourAsync(userId, description);
|
||||
RServiceResult<RUserBehaviourLog> result = await _appUserService.LogUserBehaviourAsync(userCause.UserId, userCause.Cause);
|
||||
if (!string.IsNullOrEmpty(result.ExceptionString))
|
||||
return BadRequest(result.ExceptionString);
|
||||
return Ok(result.Result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// kick out a user
|
||||
/// </summary>
|
||||
/// <param name="userCause"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Policy = SecurableItem.UserEntityShortName + ":" + SecurableItem.Administer)]
|
||||
[Route("kickout")]
|
||||
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof(RUserBehaviourLog))]
|
||||
[ProducesResponseType((int)HttpStatusCode.BadRequest, Type = typeof(string))]
|
||||
[ProducesResponseType((int)HttpStatusCode.NotFound)]
|
||||
public async Task<IActionResult> KickOutUserAsync([FromBody] UserCauseViewModel userCause)
|
||||
{
|
||||
RServiceResult<PublicRAppUser> userInfo = await _appUserService.GetUserInformation(userCause.UserId);
|
||||
if (userInfo.Result == null)
|
||||
{
|
||||
if (string.IsNullOrEmpty(userInfo.ExceptionString))
|
||||
return NotFound();
|
||||
return BadRequest(userInfo.ExceptionString);
|
||||
}
|
||||
|
||||
await _appUserService.BanUserFromSigningUpAgainAsync(userCause.UserId, userCause.Cause);
|
||||
await _appUserService.DeleteUser(userCause.UserId);
|
||||
|
||||
try
|
||||
{
|
||||
await _emailSender.SendEmailAsync
|
||||
(
|
||||
userInfo.Result.Email,
|
||||
_appUserService.GetEmailSubject(RVerifyQueueType.KickOutUser, ""),
|
||||
_appUserService.GetEmailHtmlContent(RVerifyQueueType.KickOutUser, userCause.Cause, "")
|
||||
);
|
||||
return Ok();
|
||||
}
|
||||
catch (Exception exp)
|
||||
{
|
||||
return BadRequest("Error sending email: " + exp.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// IAppUserService instance
|
||||
/// </summary>
|
||||
|
||||
@ -16,6 +16,10 @@
|
||||
/// <summary>
|
||||
/// delete user by himself/hersef
|
||||
/// </summary>
|
||||
UserSelfDelete = 2
|
||||
UserSelfDelete = 2,
|
||||
/// <summary>
|
||||
/// kick out user
|
||||
/// </summary>
|
||||
KickOutUser = 3
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
using System;
|
||||
|
||||
namespace RSecurityBackend.Models.Auth.ViewModels
|
||||
{
|
||||
/// <summary>
|
||||
/// User/Cause used for logging a user (bad) behaviour or kicking out him or her
|
||||
/// </summary>
|
||||
public class UserCauseViewModel
|
||||
{
|
||||
/// <summary>
|
||||
/// User Id
|
||||
/// </summary>
|
||||
public Guid UserId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// cause
|
||||
/// </summary>
|
||||
public string Cause { get; set; }
|
||||
}
|
||||
}
|
||||
@ -269,12 +269,18 @@
|
||||
<param name="pwd"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Controllers.AppUserControllerBase.LogUserBehaviourAsync(System.Guid,System.String)">
|
||||
<member name="M:RSecurityBackend.Controllers.AppUserControllerBase.LogUserBehaviourAsync(RSecurityBackend.Models.Auth.ViewModels.UserCauseViewModel)">
|
||||
<summary>
|
||||
log user bad behaviuor
|
||||
</summary>
|
||||
<param name="userId"></param>
|
||||
<param name="description"></param>
|
||||
<param name="userCause"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="M:RSecurityBackend.Controllers.AppUserControllerBase.KickOutUserAsync(RSecurityBackend.Models.Auth.ViewModels.UserCauseViewModel)">
|
||||
<summary>
|
||||
kick out a user
|
||||
</summary>
|
||||
<param name="userCause"></param>
|
||||
<returns></returns>
|
||||
</member>
|
||||
<member name="F:RSecurityBackend.Controllers.AppUserControllerBase._appUserService">
|
||||
@ -1132,6 +1138,11 @@
|
||||
delete user by himself/hersef
|
||||
</summary>
|
||||
</member>
|
||||
<member name="F:RSecurityBackend.Models.Auth.Db.RVerifyQueueType.KickOutUser">
|
||||
<summary>
|
||||
kick out user
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RSecurityBackend.Models.Auth.Memory.SecurableItem">
|
||||
<summary>
|
||||
securable itmes: forms and ...
|
||||
@ -1636,6 +1647,21 @@
|
||||
CallbackUrl
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RSecurityBackend.Models.Auth.ViewModels.UserCauseViewModel">
|
||||
<summary>
|
||||
User/Cause used for logging a user (bad) behaviour or kicking out him or her
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RSecurityBackend.Models.Auth.ViewModels.UserCauseViewModel.UserId">
|
||||
<summary>
|
||||
User Id
|
||||
</summary>
|
||||
</member>
|
||||
<member name="P:RSecurityBackend.Models.Auth.ViewModels.UserCauseViewModel.Cause">
|
||||
<summary>
|
||||
cause
|
||||
</summary>
|
||||
</member>
|
||||
<member name="T:RSecurityBackend.Models.Auth.ViewModels.VerifiedSignUpViewModel">
|
||||
<summary>
|
||||
verified sign up view model
|
||||
|
||||
@ -1581,7 +1581,7 @@ namespace RSecurityBackend.Services.Implementation
|
||||
/// <param name="secretCode"></param>
|
||||
public virtual string GetEmailSubject(RVerifyQueueType op, string secretCode)
|
||||
{
|
||||
string opString = op == RVerifyQueueType.SignUp ? "SignUp" : op == RVerifyQueueType.ForgotPassword ? "Forgot Password" : "Self Delete User";
|
||||
string opString = op == RVerifyQueueType.SignUp ? "SignUp" : op == RVerifyQueueType.ForgotPassword ? "Forgot Password" : op == RVerifyQueueType.KickOutUser ? "User Removal" : "Self Delete User";
|
||||
return $"Ganjoor {opString} Code:{secretCode}";
|
||||
}
|
||||
|
||||
@ -1594,10 +1594,10 @@ namespace RSecurityBackend.Services.Implementation
|
||||
/// <returns>html content</returns>
|
||||
public virtual string GetEmailHtmlContent(RVerifyQueueType op, string secretCode, string signupCallbackUrl)
|
||||
{
|
||||
if (string.IsNullOrEmpty(signupCallbackUrl))
|
||||
if (!string.IsNullOrEmpty(signupCallbackUrl))
|
||||
return $"{signupCallbackUrl}?secret={secretCode}";
|
||||
string opString = op == RVerifyQueueType.SignUp ? "ثبت نام" : op == RVerifyQueueType.ForgotPassword ? "فراموشی رمز" : "حذف کاربر";
|
||||
return $"لطفا {secretCode} را در صفحهٔ {opString} وارد کنید.";
|
||||
return op == RVerifyQueueType.KickOutUser ? $"حساب کاربری شما به دلیل {secretCode} حذف شد." : $"لطفا {secretCode} را در صفحهٔ {opString} وارد کنید.";
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Loading…
Reference in New Issue
Block a user