Press n or j to go to the next uncovered block, b, p or k for the previous block.
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 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 403x 403x 401x 401x 401x 44x 16x 4x 77x 48x 11x 65x 28x 44x 28x 44x 409x 409x 409x 44x 365x 77x 288x 28x 260x 44x 216x 28x 188x 44x 144x 65x 79x 48x 31x 11x 20x 4x 16x 16x 175x | import makeDebug from 'debug'; import { BadRequest } from '@feathersjs/errors'; import { AuthenticationManagementBase } from './AuthenticationManagementBase'; import ensureHasAllKeys from '../helpers/ensure-has-all-keys'; import { makeDefaultOptions } from '.'; import checkUnique from '../methods/check-unique'; import identityChange from '../methods/identity-change'; import passwordChange from '../methods/password-change'; import resendVerifySignup from '../methods/resend-verify-signup'; import { resetPwdWithLongToken, resetPwdWithShortToken } from '../methods/reset-password'; import sendResetPwd from '../methods/send-reset-pwd'; import { verifySignupWithLongToken, verifySignupWithShortToken } from '../methods/verify-signup'; import { verifySignupSetPasswordWithLongToken, verifySignupSetPasswordWithShortToken } from '../methods/verify-signup-set-password'; import type { SetRequired } from 'type-fest'; import type { AuthenticationManagementData, AuthenticationManagementServiceOptions, DataCheckUnique, DataCheckUniqueWithAction, DataIdentityChange, DataIdentityChangeWithAction, DataOptions, DataPasswordChange, DataPasswordChangeWithAction, DataResendVerifySignup, DataResendVerifySignupWithAction, DataResetPwdLong, DataResetPwdLongWithAction, DataResetPwdShort, DataResetPwdShortWithAction, DataSendResetPwd, DataSendResetPwdWithAction, DataVerifySignupLong, DataVerifySignupLongWithAction, DataVerifySignupSetPasswordLong, DataVerifySignupSetPasswordLongWithAction, DataVerifySignupSetPasswordShort, DataVerifySignupSetPasswordShortWithAction, DataVerifySignupShort, DataVerifySignupShortWithAction, SanitizedUser } from '../types'; const debug = makeDebug('authLocalMgnt:service'); type AllResultTypes = null | SanitizedUser | AuthenticationManagementServiceOptions | unknown; export class AuthenticationManagementService extends AuthenticationManagementBase<AuthenticationManagementData, AllResultTypes> { docs: unknown; options: AuthenticationManagementServiceOptions; constructor ( options: SetRequired<Partial<AuthenticationManagementServiceOptions>, 'app'>, docs?: unknown ) { super(); ensureHasAllKeys(options, ['app'], this.constructor.name); const defaultOptions: Omit<AuthenticationManagementServiceOptions, 'app'> = makeDefaultOptions([ 'service', 'skipIsVerifiedCheck', 'notifier', 'longTokenLen', 'shortTokenLen', 'shortTokenDigits', 'resetDelay', 'delay', 'resetAttempts', 'reuseResetToken', 'identifyUserProps', 'sanitizeUserForClient', 'passwordField' ]); this.options = Object.assign(defaultOptions, options); this.docs = docs; } async _checkUnique (data: DataCheckUnique): Promise<unknown> { return await checkUnique( this.options, data.value, data.ownId, data.meta ); } async checkUnique (data: DataCheckUnique): Promise<unknown> { return await this._checkUnique(data); } async _identityChange (data: DataIdentityChange): Promise<SanitizedUser> { return await identityChange( this.options, data.value.user, data.value.password, data.value.changes, data.notifierOptions ); } async identyChange (data: DataIdentityChange): Promise<SanitizedUser> { return await this._identityChange(data); } async _passwordChange (data: DataPasswordChange): Promise<SanitizedUser> { return await passwordChange( this.options, data.value.user, data.value.oldPassword, data.value.password, data.notifierOptions ); } async passwordChange (data: DataPasswordChange): Promise<SanitizedUser> { return await this._passwordChange(data); } async _resendVerifySignup (data: DataResendVerifySignup): Promise<SanitizedUser> { return await resendVerifySignup( this.options, data.value, data.notifierOptions ); } async resendVerifySignup (data: DataResendVerifySignup): Promise<SanitizedUser> { return await this._resendVerifySignup(data); } async _resetPasswordLong (data: DataResetPwdLong): Promise<SanitizedUser> { return await resetPwdWithLongToken( this.options, data.value.token, data.value.password, data.notifierOptions ); } async resetPasswordLong (data: DataResetPwdLong): Promise<SanitizedUser> { return await this._resetPasswordLong(data); } async _resetPasswordShort (data: DataResetPwdShort): Promise<SanitizedUser> { return await resetPwdWithShortToken( this.options, data.value.token, data.value.user, data.value.password, data.notifierOptions ); } async resetPasswordShort (data: DataResetPwdShort): Promise<SanitizedUser> { return await this._resetPasswordShort(data); } async _sendResetPassword (data: DataSendResetPwd): Promise<SanitizedUser> { return await sendResetPwd( this.options, data.value, data.notifierOptions ); } async sendResetPassword (data: DataSendResetPwd): Promise<SanitizedUser> { return await this._sendResetPassword(data); } async _verifySignupLong (data: DataVerifySignupLong): Promise<SanitizedUser> { return await verifySignupWithLongToken( this.options, data.value, data.notifierOptions ); } async verifySignupLong (data: DataVerifySignupLong): Promise<SanitizedUser> { return await this._verifySignupLong(data); } async _verifySignupShort (data: DataVerifySignupShort): Promise<SanitizedUser> { return await verifySignupWithShortToken( this.options, data.value.token, data.value.user, data.notifierOptions ); } async verifySignupShort (data: DataVerifySignupShort): Promise<SanitizedUser> { return await this._verifySignupShort(data); } async _verifySignupSetPasswordLong (data: DataVerifySignupSetPasswordLong): Promise<SanitizedUser> { return await verifySignupSetPasswordWithLongToken( this.options, data.value.token, data.value.password, data.notifierOptions ); } async verifySignupSetPasswordLong (data: DataVerifySignupSetPasswordLong): Promise<SanitizedUser> { return await this._verifySignupSetPasswordLong(data); } async _verifySignupSetPasswordShort (data: DataVerifySignupSetPasswordShort): Promise<SanitizedUser> { return await verifySignupSetPasswordWithShortToken( this.options, data.value.token, data.value.user, data.value.password, data.notifierOptions ); } async verifySignupSetPasswordShort (data: DataVerifySignupSetPasswordShort): Promise<SanitizedUser> { return await this._verifySignupSetPasswordShort(data); } /** * check props are unique in the users items. * @param data.action action is 'checkUnique' * @param data.value {IdentifyUser} the user with properties, e.g. {email, username}. Props with null or undefined are ignored. * @param data.ownId excludes your current user from the search * @param data.meta.noErrMsg if return an error.message if not unique */ // eslint-disable-next-line @typescript-eslint/no-unused-vars async _create ({ action, value, ownId, meta }: DataCheckUniqueWithAction): Promise<null> /** * change communications * @param action action is 'identityChange' * @param value { changes, password, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataIdentityChangeWithAction): Promise<SanitizedUser> /** * change password * @param action action is 'passwordChange' * @param value { oldPassword, password, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataPasswordChangeWithAction): Promise<SanitizedUser> /** * resend sign up verification notification * @param action action is 'resendVerifySignup' * @param value {IdentifyUser} the user with properties, e.g. {email}, {token: verifyToken} * @param notifierOptions options passed to options.notifier, e.g. {preferredComm: 'cellphone'} */ async _create ({ action, value, notifierOptions }: DataResendVerifySignupWithAction): Promise<SanitizedUser> /** * forgotten password verification with long token * @param action action is 'resetPwdLong' * @param value { password, token, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataResetPwdLongWithAction): Promise<SanitizedUser> /** * forgotten password verification with short token * @param action action is 'resetPwdShort' * @param value { password, token, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataResetPwdShortWithAction): Promise<SanitizedUser> /** * send forgotten password notification * @param action action is 'sendResetPwd' * @param value { password, token } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataSendResetPwdWithAction): Promise<SanitizedUser> /** * sign up or identityChange verification with long token * @param action action is 'verifySignupLong' * @param value // compares to user.verifyToken * @param notifierOptions options passed to options.notifier, e.g. {preferredComm: 'cellphone'} */ async _create ({ action, value, notifierOptions }: DataVerifySignupLongWithAction): Promise<SanitizedUser> /** * sign up or identityChange verification with short token * @param action action is 'verifySignupShort' * @param value { token, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataVerifySignupShortWithAction): Promise<SanitizedUser> /** * sign up verification and set password with long token * @param action action is 'verifySignupSetPasswordLong' * @param value { password, token } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataVerifySignupSetPasswordLongWithAction): Promise<SanitizedUser> /** * sign up verification and set password with short token * @param action action is 'verifySignupSetPasswordShort' * @param value { password, token, user } * @param notifierOptions */ async _create ({ action, value, notifierOptions }: DataVerifySignupSetPasswordShortWithAction): Promise<SanitizedUser> /** * get options for AuthenticationManagement * @param action action is 'options' */ async _create ({ action }: DataOptions): Promise<AuthenticationManagementServiceOptions> async _create (data: AuthenticationManagementData): Promise<AllResultTypes> { debug(`create called. action=${data.action}`); try { if (data.action === 'checkUnique') { return await this._checkUnique(data); } else if (data.action === 'resendVerifySignup') { return await this._resendVerifySignup(data); } else if (data.action === 'verifySignupLong') { return await this._verifySignupLong(data); } else if (data.action === 'verifySignupShort') { return await this._verifySignupShort(data); } else if (data.action === 'verifySignupSetPasswordLong') { return await this._verifySignupSetPasswordLong(data); } else if (data.action === 'verifySignupSetPasswordShort') { return await this._verifySignupSetPasswordShort(data); } else if (data.action === 'sendResetPwd') { return await this._sendResetPassword(data); } else if (data.action === 'resetPwdLong') { return await this._resetPasswordLong(data); } else if (data.action === 'resetPwdShort') { return await this._resetPasswordShort(data); } else if (data.action === 'passwordChange') { return await this._passwordChange(data); } else Eif (data.action === 'identityChange') { return await this._identityChange(data); } else if (data.action === 'options') { return this.options; } } catch (err) { return await Promise.reject(err); } throw new BadRequest( //@ts-expect-error action is of type never // eslint-disable-next-line @typescript-eslint/restrict-template-expressions `Action '${data.action}' is invalid.`, { errors: { $className: 'badParams' } } ); } } |