/
IdentityErrorDescriber.cs
312 lines (289 loc) · 13.2 KB
/
IdentityErrorDescriber.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.Extensions.Identity.Core;
namespace Microsoft.AspNetCore.Identity
{
/// <summary>
/// Service to enable localization for application facing identity errors.
/// </summary>
/// <remarks>
/// These errors are returned to controllers and are generally used as display messages to end users.
/// </remarks>
public class IdentityErrorDescriber
{
/// <summary>
/// Returns the default <see cref="IdentityError"/>.
/// </summary>
/// <returns>The default <see cref="IdentityError"/>.</returns>
public virtual IdentityError DefaultError()
{
return new IdentityError
{
Code = nameof(DefaultError),
Description = Resources.DefaultError
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a concurrency failure.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a concurrency failure.</returns>
public virtual IdentityError ConcurrencyFailure()
{
return new IdentityError
{
Code = nameof(ConcurrencyFailure),
Description = Resources.ConcurrencyFailure
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password mismatch.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a password mismatch.</returns>
public virtual IdentityError PasswordMismatch()
{
return new IdentityError
{
Code = nameof(PasswordMismatch),
Description = Resources.PasswordMismatch
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating an invalid token.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating an invalid token.</returns>
public virtual IdentityError InvalidToken()
{
return new IdentityError
{
Code = nameof(InvalidToken),
Description = Resources.InvalidToken
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a recovery code was not redeemed.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a recovery code was not redeemed.</returns>
public virtual IdentityError RecoveryCodeRedemptionFailed()
{
return new IdentityError
{
Code = nameof(RecoveryCodeRedemptionFailed),
Description = Resources.RecoveryCodeRedemptionFailed
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating an external login is already associated with an account.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating an external login is already associated with an account.</returns>
public virtual IdentityError LoginAlreadyAssociated()
{
return new IdentityError
{
Code = nameof(LoginAlreadyAssociated),
Description = Resources.LoginAlreadyAssociated
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified user <paramref name="userName"/> is invalid.
/// </summary>
/// <param name="userName">The user name that is invalid.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specified user <paramref name="userName"/> is invalid.</returns>
public virtual IdentityError InvalidUserName(string userName)
{
return new IdentityError
{
Code = nameof(InvalidUserName),
Description = Resources.FormatInvalidUserName(userName)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified <paramref name="email"/> is invalid.
/// </summary>
/// <param name="email">The email that is invalid.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specified <paramref name="email"/> is invalid.</returns>
public virtual IdentityError InvalidEmail(string email)
{
return new IdentityError
{
Code = nameof(InvalidEmail),
Description = Resources.FormatInvalidEmail(email)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified <paramref name="userName"/> already exists.
/// </summary>
/// <param name="userName">The user name that already exists.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specified <paramref name="userName"/> already exists.</returns>
public virtual IdentityError DuplicateUserName(string userName)
{
return new IdentityError
{
Code = nameof(DuplicateUserName),
Description = Resources.FormatDuplicateUserName(userName)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified <paramref name="email"/> is already associated with an account.
/// </summary>
/// <param name="email">The email that is already associated with an account.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specified <paramref name="email"/> is already associated with an account.</returns>
public virtual IdentityError DuplicateEmail(string email)
{
return new IdentityError
{
Code = nameof(DuplicateEmail),
Description = Resources.FormatDuplicateEmail(email)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified <paramref name="role"/> name is invalid.
/// </summary>
/// <param name="role">The invalid role.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specific role <paramref name="role"/> name is invalid.</returns>
public virtual IdentityError InvalidRoleName(string role)
{
return new IdentityError
{
Code = nameof(InvalidRoleName),
Description = Resources.FormatInvalidRoleName(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating the specified <paramref name="role"/> name already exists.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating the specific role <paramref name="role"/> name already exists.</returns>
public virtual IdentityError DuplicateRoleName(string role)
{
return new IdentityError
{
Code = nameof(DuplicateRoleName),
Description = Resources.FormatDuplicateRoleName(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user already has a password.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a user already has a password.</returns>
public virtual IdentityError UserAlreadyHasPassword()
{
return new IdentityError
{
Code = nameof(UserAlreadyHasPassword),
Description = Resources.UserAlreadyHasPassword
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating user lockout is not enabled.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating user lockout is not enabled.</returns>
public virtual IdentityError UserLockoutNotEnabled()
{
return new IdentityError
{
Code = nameof(UserLockoutNotEnabled),
Description = Resources.UserLockoutNotEnabled
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is already in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is already in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserAlreadyInRole(string role)
{
return new IdentityError
{
Code = nameof(UserAlreadyInRole),
Description = Resources.FormatUserAlreadyInRole(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.
/// </summary>
/// <param name="role">The duplicate role.</param>
/// <returns>An <see cref="IdentityError"/> indicating a user is not in the specified <paramref name="role"/>.</returns>
public virtual IdentityError UserNotInRole(string role)
{
return new IdentityError
{
Code = nameof(UserNotInRole),
Description = Resources.FormatUserNotInRole(role)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password of the specified <paramref name="length"/> does not meet the minimum length requirements.
/// </summary>
/// <param name="length">The length that is not long enough.</param>
/// <returns>An <see cref="IdentityError"/> indicating a password of the specified <paramref name="length"/> does not meet the minimum length requirements.</returns>
public virtual IdentityError PasswordTooShort(int length)
{
return new IdentityError
{
Code = nameof(PasswordTooShort),
Description = Resources.FormatPasswordTooShort(length)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password does not meet the minimum number <paramref name="uniqueChars"/> of unique chars.
/// </summary>
/// <param name="uniqueChars">The number of different chars that must be used.</param>
/// <returns>An <see cref="IdentityError"/> indicating a password does not meet the minimum number <paramref name="uniqueChars"/> of unique chars.</returns>
public virtual IdentityError PasswordRequiresUniqueChars(int uniqueChars)
{
return new IdentityError
{
Code = nameof(PasswordRequiresUniqueChars),
Description = Resources.FormatPasswordRequiresUniqueChars(uniqueChars)
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password entered does not contain a non-alphanumeric character, which is required by the password policy.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a password entered does not contain a non-alphanumeric character.</returns>
public virtual IdentityError PasswordRequiresNonAlphanumeric()
{
return new IdentityError
{
Code = nameof(PasswordRequiresNonAlphanumeric),
Description = Resources.PasswordRequiresNonAlphanumeric
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password entered does not contain a numeric character, which is required by the password policy.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a password entered does not contain a numeric character.</returns>
public virtual IdentityError PasswordRequiresDigit()
{
return new IdentityError
{
Code = nameof(PasswordRequiresDigit),
Description = Resources.PasswordRequiresDigit
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password entered does not contain a lower case letter, which is required by the password policy.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a password entered does not contain a lower case letter.</returns>
public virtual IdentityError PasswordRequiresLower()
{
return new IdentityError
{
Code = nameof(PasswordRequiresLower),
Description = Resources.PasswordRequiresLower
};
}
/// <summary>
/// Returns an <see cref="IdentityError"/> indicating a password entered does not contain an upper case letter, which is required by the password policy.
/// </summary>
/// <returns>An <see cref="IdentityError"/> indicating a password entered does not contain an upper case letter.</returns>
public virtual IdentityError PasswordRequiresUpper()
{
return new IdentityError
{
Code = nameof(PasswordRequiresUpper),
Description = Resources.PasswordRequiresUpper
};
}
}
}