mirror of
https://github.com/open5gs/open5gs.git
synced 2026-05-05 23:37:22 +00:00
DB table name change from User to Account
This commit is contained in:
parent
8b41158cc8
commit
d25b45bf1c
4 changed files with 21 additions and 21 deletions
|
|
@ -24,16 +24,16 @@ app.prepare()
|
|||
const server = express();
|
||||
|
||||
// FIXME : we need to implement landing page for adding admin account
|
||||
models.UserRole.count().then(c => {
|
||||
models.AccountRole.count().then(c => {
|
||||
if (c == 0) {
|
||||
models.UserRole.create({
|
||||
models.AccountRole.create({
|
||||
role: 'admin',
|
||||
Users: [{
|
||||
Accounts: [{
|
||||
username: 'admin',
|
||||
password: '1423'
|
||||
}]
|
||||
}, {
|
||||
include: [ models.UserRole.User ]
|
||||
include: [ models.AccountRole.Account ]
|
||||
});
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
const User = sequelize.define('User', {
|
||||
const Account = sequelize.define('Account', {
|
||||
username: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
|
|
@ -15,7 +15,7 @@ module.exports = (sequelize, DataTypes) => {
|
|||
}, {
|
||||
classMethods: {
|
||||
associate: models => {
|
||||
User.UserRole = User.belongsTo(models.UserRole, {
|
||||
Account.AccountRole = Account.belongsTo(models.AccountRole, {
|
||||
onDelete: 'CASCADE',
|
||||
foreignKey: {
|
||||
allowNull: false
|
||||
|
|
@ -26,5 +26,5 @@ module.exports = (sequelize, DataTypes) => {
|
|||
freezeTableName: true
|
||||
});
|
||||
|
||||
return User;
|
||||
return Account;
|
||||
};
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
module.exports = (sequelize, DataTypes) => {
|
||||
const UserRole = sequelize.define('UserRole', {
|
||||
const AccountRole = sequelize.define('AccountRole', {
|
||||
role: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
|
|
@ -11,11 +11,11 @@ module.exports = (sequelize, DataTypes) => {
|
|||
}, {
|
||||
classMethods: {
|
||||
associate: models => {
|
||||
UserRole.User = UserRole.hasMany(models.User);
|
||||
AccountRole.Account = AccountRole.hasMany(models.Account);
|
||||
}
|
||||
},
|
||||
freezeTableName: true
|
||||
});
|
||||
|
||||
return UserRole;
|
||||
return AccountRole;
|
||||
};
|
||||
|
|
@ -4,29 +4,29 @@ const LocalStrategy = require('passport-local').Strategy;
|
|||
const models = require('../models');
|
||||
|
||||
passport.use(new LocalStrategy((username, password, done) => {
|
||||
models.User.findOne({ where: {username: username} }).then(user => {
|
||||
if (!user) {
|
||||
models.Account.findOne({ where: {username: username} }).then(account => {
|
||||
if (!account) {
|
||||
return done(null, false, { message: 'Incorrect username' });
|
||||
}
|
||||
if (user.password != password) {
|
||||
if (account.password != password) {
|
||||
return done(null, false, { message: 'Incorrect password' });
|
||||
}
|
||||
return done(null, user);
|
||||
return done(null, account);
|
||||
});
|
||||
}));
|
||||
|
||||
passport.serializeUser((user, done) => {
|
||||
done(null, user.id);
|
||||
passport.serializeUser((account, done) => {
|
||||
done(null, account.id);
|
||||
})
|
||||
|
||||
passport.deserializeUser((id, done) => {
|
||||
models.User.findOne({
|
||||
models.Account.findOne({
|
||||
where: { id: id },
|
||||
include: [{ model: models.UserRole }]
|
||||
}).then(user => {
|
||||
include: [{ model: models.AccountRole }]
|
||||
}).then(account => {
|
||||
done(null, {
|
||||
username: user.username,
|
||||
role: user.UserRole.role
|
||||
username: account.username,
|
||||
role: account.AccountRole.role
|
||||
});
|
||||
})
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue