Skip to content

Commit

Permalink
Merge pull request #868 from colinin/fix-email-confirm
Browse files Browse the repository at this point in the history
fix: fix email confirm link
  • Loading branch information
colinin authored Aug 31, 2023
2 parents c8ad940 + b484dde commit 2a1d759
Show file tree
Hide file tree
Showing 24 changed files with 225 additions and 47 deletions.
2 changes: 1 addition & 1 deletion apps/vue/run.bat
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
title abp-next-admin-vben
npm run dev
pnpm dev
5 changes: 5 additions & 0 deletions apps/vue/src/api/account/model/profilesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,8 @@ export interface SendEmailConfirmCode {
returnUrl?: string;
returnUrlHash?: string;
}

export interface ConfirmEmailInput {
userId?: string;
confirmToken: string;
}
9 changes: 9 additions & 0 deletions apps/vue/src/api/account/profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
ChangePhoneNumber,
TwoFactorEnabled,
SendEmailConfirmCode,
ConfirmEmailInput,
} from './model/profilesModel';

enum Api {
Expand All @@ -17,6 +18,7 @@ enum Api {
GetTwoFactorEnabled = '/api/account/my-profile/two-factor',
ChangeTwoFactorEnabled = '/api/account/my-profile/change-two-factor',
SendEmailConfirmLink = '/api/account/my-profile/send-email-confirm-link',
ConfirmEmail = '/api/account/my-profile/confirm-email',
}

export const get = () => {
Expand Down Expand Up @@ -46,6 +48,13 @@ export const sendEmailConfirmLink = (input: SendEmailConfirmCode) => {
});
};

export const confirmEmail = (input: ConfirmEmailInput) => {
return defAbpHttp.put<void>({
url: Api.ConfirmEmail,
data: input,
});
};

export const sendChangePhoneNumberCode = (phoneNumber: string) => {
return defAbpHttp.post<void>({
url: Api.SendChangePhoneNumberCode,
Expand Down
3 changes: 2 additions & 1 deletion apps/vue/src/locales/lang/en/routes/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default {
errorLogList: 'Error Log',
accountSetting: 'Account Setting',
accountCenter: 'Account Center',
accountSecurityLogs: 'Security Logs'
accountSecurityLogs: 'Security Logs',
accountEmailConfirm: 'Email Confirm'
};
3 changes: 2 additions & 1 deletion apps/vue/src/locales/lang/zh-CN/routes/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ export default {
errorLogList: '错误日志列表',
accountSetting: '个人设置',
accountCenter: '个人中心',
accountSecurityLogs: '安全日志'
accountSecurityLogs: '安全日志',
accountEmailConfirm: '邮件确认'
};
10 changes: 10 additions & 0 deletions apps/vue/src/router/routes/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ export const ACCOUNT_CENTER_ROUTE: AppRouteRecordRaw = {
ignoreAuth: true,
},
},
{
path: 'email-confirm',
name: 'email-confirm',
component: () => import('/@/views/account/email-confirm/index.vue'),
meta: {
title: t('routes.basic.accountEmailConfirm'),
hideMenu: true,
ignoreAuth: true,
},
},
],
};

67 changes: 67 additions & 0 deletions apps/vue/src/views/account/email-confirm/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<div class="container">
<BasicForm @register="registerForm" />
</div>
</template>

<script lang="ts" setup>
import { onMounted } from 'vue';
import { useRoute } from "vue-router";
import { useI18n } from "/@/hooks/web/useI18n";
import { BasicForm, useForm } from '/@/components/Form/index';
import { confirmEmail } from '/@/api/account/profiles';
const route = useRoute();
const { t } = useI18n();
const [registerForm, { setFieldsValue, getFieldsValue }] = useForm({
labelWidth: 120,
showResetButton: false,
showSubmitButton: true,
submitButtonOptions: {
text: t('common.okText'),
},
submitFunc: handleSubmit,
showAdvancedButton: false,
showActionButtonGroup: true,
schemas: [
{
field: 'userId',
component: 'Input',
label: 'userId',
show: false
},
{
field: 'confirmToken',
component: 'Input',
label: 'confirmToken',
show: false
},
{
field: 'returnUrl',
component: 'Input',
label: 'returnUrl',
show: false
},
],
});
onMounted(() => {
setFieldsValue(route.query);
});
function handleSubmit(): Promise<void> {
var input = getFieldsValue();
return confirmEmail({
userId: input.userId,
confirmToken: input.confirmToken,
}).then(() => {
if (input.returnUrl) {
window.location.href = input.returnUrl;
}
});
}
</script>

<style scoped>
</style>
2 changes: 1 addition & 1 deletion apps/vue/src/views/account/setting/SecureSetting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
:loading="item.loading"
@change="handleChange(item, $event)"
/>
<Button v-else-if="item.extra" class="extra" type="link" :loading="item.loading" :disbled="!item.enabled" @click="toggleCommand(item)">
<Button v-else-if="item.extra && item.enabled !== false" class="extra" type="link" :loading="item.loading" @click="toggleCommand(item)">
{{ item.extra }}
</Button>
</template>
Expand Down
25 changes: 18 additions & 7 deletions apps/vue/src/views/sys/login/PortalForm.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@
layout="vertical"
@keypress.enter="handleLogin"
>
<FormItem name="userName" class="enter-x" :label="t('AbpAccount.DisplayName:UserName')">
<FormItem name="userName" class="enter-x" :label="L('DisplayName:UserName')">
<BInput
size="large"
v-model:value="formData.userName"
:placeholder="t('AbpAccount.DisplayName:UserName')"
:placeholder="L('DisplayName:UserName')"
class="fix-auto-fill"
/>
</FormItem>
<FormItem name="password" class="enter-x" :label="t('AbpAccount.DisplayName:Password')">
<FormItem name="password" class="enter-x" :label="L('DisplayName:Password')">
<InputPassword
size="large"
visibilityToggle
autocomplete="off"
v-model:value="formData.password"
:placeholder="t('AbpAccount.DisplayName:Password')"
:placeholder="L('DisplayName:Password')"
/>
</FormItem>

Expand Down Expand Up @@ -54,6 +54,7 @@
</template>
</List>
</BasicModal>
<TwoFactorModal @register="registerTwoFactorModal" />
</template>
</template>
<script lang="ts" setup>
Expand All @@ -69,6 +70,7 @@
import { useMessage } from '/@/hooks/web/useMessage';
import { useGlobSetting } from '/@/hooks/setting';
import { PortalLoginModel } from '/@/api/sys/model/userModel';
import TwoFactorModal from './TwoFactorModal.vue';
const FormItem = Form.Item;
const InputPassword = Input.Password;
Expand All @@ -77,6 +79,7 @@
const { notification } = useMessage();
const [registerModal, { openModal, closeModal }] = useModal();
const [registerTwoFactorModal, { openModal: openTwoFactorModal }] = useModal();
const { t } = useI18n();
const { L } = useLocalization('AbpAccount');
const { handleBackLogin, getLoginState } = useLoginState();
Expand Down Expand Up @@ -134,9 +137,17 @@
duration: 3,
});
}
} catch (error) {
portalModel.value = JSON.parse(error as string) as PortalLoginModel[];
openModal(true);
} catch (error: any) {
if (error.userId && error.twoFactorToken) {
openTwoFactorModal(true, {
userId: error.userId,
userName: data.userName,
password: data.password,
});
} else {
portalModel.value = JSON.parse(error as string) as PortalLoginModel[];
openModal(true);
}
// createConfirm({
// iconType: 'info',
// title: '请选择登陆平台',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations;

namespace LINGYUN.Abp.Account;

public class ConfirmEmailInput
{
[Required]
public Guid UserId { get; set; }

[Required]
public string ConfirmToken { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Volo.Abp.Caching;
using Volo.Abp.Identity;
using Volo.Abp.Settings;
using Volo.Abp.Users;

namespace LINGYUN.Abp.Account
{
Expand Down Expand Up @@ -138,7 +139,7 @@ public async virtual Task ConfirmEmailAsync(ConfirmEmailInput input)
{
await IdentityOptions.SetAsync();

var user = await UserManager.GetByIdAsync(input.UserId);
var user = await UserManager.GetByIdAsync(CurrentUser.GetId());

(await UserManager.ConfirmEmailAsync(user, input.ConfirmToken)).CheckErrors();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Volo.Abp.IdentityServer.Domain" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LINGYUN.Platform;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.IdentityServer;
using Volo.Abp.IdentityServer.Localization;
using Volo.Abp.Localization;
Expand All @@ -10,6 +11,7 @@ namespace LINGYUN.Abp.IdentityServer.Portal;

[DependsOn(
typeof(AbpIdentityServerDomainModule),
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(PlatformDomainModule))]
public class AbpIdentityServerPortalModule : AbpModule
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using IdentityServer4.Services;
using IdentityServer4.Validation;
using LINGYUN.Platform.Portal;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Identity;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
Expand All @@ -14,6 +15,7 @@
using System.Linq;
using System.Security.Claims;
using System.Threading.Tasks;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Identity;
using Volo.Abp.IdentityServer;
using Volo.Abp.MultiTenancy;
Expand All @@ -40,6 +42,9 @@ public class PortalGrantValidator : IExtensionGrantValidator
private readonly ICurrentTenant _currentTenant;
private readonly IEnterpriseRepository _enterpriseRepository;

private readonly AbpAspNetCoreMultiTenancyOptions _multiTenancyOptions;
private readonly IHttpContextAccessor _httpContextAccessor;

public PortalGrantValidator(
ILogger<PortalGrantValidator> logger,
IOptions<IdentityServerOptions> options,
Expand All @@ -48,7 +53,9 @@ public PortalGrantValidator(
IdentitySecurityLogManager identitySecurityLogManager,
UserManager<IdentityUser> userManager,
ICurrentTenant currentTenant,
IEnterpriseRepository enterpriseRepository)
IEnterpriseRepository enterpriseRepository,
IOptions<AbpAspNetCoreMultiTenancyOptions> multiTenancyOptions,
IHttpContextAccessor httpContextAccessor)
{
_logger = logger;
_options = options.Value;
Expand All @@ -58,6 +65,8 @@ public PortalGrantValidator(
_userManager = userManager;
_currentTenant = currentTenant;
_enterpriseRepository = enterpriseRepository;
_multiTenancyOptions = multiTenancyOptions.Value;
_httpContextAccessor = httpContextAccessor;
}

[UnitOfWork]
Expand Down Expand Up @@ -101,6 +110,14 @@ public async virtual Task ValidateAsync(ExtensionGrantValidationContext context)

using (_currentTenant.Change(tenantId))
{
if (_httpContextAccessor.HttpContext != null)
{
AbpMultiTenancyCookieHelper.SetTenantCookie(
_httpContextAccessor.HttpContext,
tenantId,
_multiTenancyOptions.TenantKey);
}

var validatedRequest = new ValidatedTokenRequest
{
Raw = parameters ?? throw new ArgumentNullException(nameof(parameters)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

<ItemGroup>
<PackageReference Include="Volo.Abp.OpenIddict.AspNetCore" Version="$(VoloAbpPackageVersion)" />
<PackageReference Include="Volo.Abp.AspNetCore.MultiTenancy" Version="$(VoloAbpPackageVersion)" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using LINGYUN.Platform;
using Microsoft.Extensions.DependencyInjection;
using Volo.Abp.AspNetCore.MultiTenancy;
using Volo.Abp.Modularity;
using Volo.Abp.OpenIddict;
using Volo.Abp.OpenIddict.ExtensionGrantTypes;
Expand All @@ -8,6 +9,7 @@ namespace LINGYUN.Abp.OpenIddict.Portal;

[DependsOn(
typeof(AbpOpenIddictAspNetCoreModule),
typeof(AbpAspNetCoreMultiTenancyModule),
typeof(PlatformDomainModule))]
public class AbpOpenIddictPortalModule : AbpModule
{
Expand Down
Loading

0 comments on commit 2a1d759

Please sign in to comment.