mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Move old backend code to old_src folder
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
c42d2223e8
commit
7b9f9a487b
97 changed files with 7 additions and 7 deletions
73
old_src/lib/web/auth/utils.ts
Normal file
73
old_src/lib/web/auth/utils.ts
Normal file
|
@ -0,0 +1,73 @@
|
|||
import { Profile } from 'passport'
|
||||
import { logger } from '../../logger'
|
||||
import { User } from '../../models'
|
||||
|
||||
export function passportGeneralCallback (
|
||||
accessToken: string,
|
||||
refreshToken: string,
|
||||
profile: Profile,
|
||||
done: (err?: Error | null, user?: User) => void
|
||||
): void {
|
||||
const stringifiedProfile = JSON.stringify(profile)
|
||||
User.findOrCreate({
|
||||
where: {
|
||||
profileid: profile.id.toString()
|
||||
},
|
||||
defaults: {
|
||||
profile: stringifiedProfile,
|
||||
accessToken: accessToken,
|
||||
refreshToken: refreshToken
|
||||
}
|
||||
}).then(function ([user, _]) {
|
||||
if (user) {
|
||||
let needSave = false
|
||||
if (user.profile !== stringifiedProfile) {
|
||||
user.profile = stringifiedProfile
|
||||
needSave = true
|
||||
}
|
||||
if (user.accessToken !== accessToken) {
|
||||
user.accessToken = accessToken
|
||||
needSave = true
|
||||
}
|
||||
if (user.refreshToken !== refreshToken) {
|
||||
user.refreshToken = refreshToken
|
||||
needSave = true
|
||||
}
|
||||
if (needSave) {
|
||||
user.save().then(function () {
|
||||
logger.debug(`user login: ${user.id}`)
|
||||
return done(null, user)
|
||||
})
|
||||
} else {
|
||||
logger.debug(`user login: ${user.id}`)
|
||||
return done(null, user)
|
||||
}
|
||||
}
|
||||
}).catch(function (err) {
|
||||
logger.error('auth callback failed: ' + err)
|
||||
return done(err, undefined)
|
||||
})
|
||||
}
|
||||
|
||||
export enum ProviderEnum {
|
||||
facebook = 'facebook',
|
||||
twitter = 'twitter',
|
||||
github = 'github',
|
||||
gitlab = 'gitlab',
|
||||
dropbox = 'dropbox',
|
||||
google = 'google',
|
||||
ldap = 'ldap',
|
||||
oauth2 = 'oauth2',
|
||||
saml = 'saml',
|
||||
}
|
||||
|
||||
export type PassportProfile = {
|
||||
id: string;
|
||||
username: string;
|
||||
displayName: string;
|
||||
emails: string[];
|
||||
avatarUrl: string;
|
||||
profileUrl: string;
|
||||
provider: ProviderEnum;
|
||||
photos: { value: string }[];
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue