Update user w/ plex token and URL

This commit is contained in:
mjrode
2019-04-05 22:32:28 -05:00
parent 2e7421f342
commit 87c1141556
13 changed files with 132 additions and 93 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ import plexService from '../services/plex';
const router = Router();
router.get('/auth', plexService.getAuthToken);
router.get('/token', plexService.getAuthToken);
router.get('/users', plexService.getUsers);
@@ -20,7 +20,7 @@ module.exports = {
type: Sequelize.STRING,
unique: true,
},
plexServerUrl: {
plexUrl: {
type: Sequelize.STRING,
},
plexToken: {
+1 -1
View File
@@ -6,7 +6,7 @@ module.exports = (sequelize, DataTypes) => {
lastName: DataTypes.STRING,
googleId: DataTypes.STRING,
email: {type: DataTypes.STRING, unique: true},
plexServerUrl: DataTypes.STRING,
plexUrl: DataTypes.STRING,
plexToken: DataTypes.STRING,
},
{},
+7 -3
View File
@@ -18,9 +18,13 @@ const encryptUserCreds = (username, password) => {
};
const fetchToken = async (username, password) => {
const res = await request.post(urlParams(username, password));
const token = res.match(rxAuthToken)[1];
return token;
try {
const res = await request.post(urlParams(username, password));
const token = res.match(rxAuthToken)[1];
return token;
} catch (error) {
return error.message;
}
};
export default fetchToken;
+16 -7
View File
@@ -1,16 +1,25 @@
import plexApi from './plexApi';
import importData from './importData';
import auth from './auth';
import models from '../../db/models';
import helpers from '../helpers';
const getAuthToken = async (req, res) => {
const {username} = req.query;
const {password} = req.query;
console.log('Mikes stuff', username, password);
const token = await auth(username, password);
// req.user.plexToken = token;
// const user = await req.user.save();
return res.json(token);
try {
const {email, password, plexUrl} = req.query;
const plexToken = await auth(email, password);
const [rowsUpdate, updatedUser] = await models.User.update(
{plexUrl, plexToken},
{returning: true, where: {googleId: req.user.googleId}},
);
console.log('updatedUser', updatedUser);
console.log('token', plexToken);
return res.json(updatedUser);
} catch (error) {
console.log(error.message);
return res.status(201).json(error.message);
}
};
const getUsers = (req, res) => {
+3 -3
View File
@@ -13,7 +13,7 @@ const getUsersUrlParams = function(token) {
const getSectionsUrlParams = function() {
return {
host: config.plex.plexServerUrl,
host: config.plex.plexUrl,
path: '/library/sections',
queryParams: {
'X-Plex-Token': config.plex.token,
@@ -23,7 +23,7 @@ const getSectionsUrlParams = function() {
const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
return {
host: config.plex.plexServerUrl,
host: config.plex.plexUrl,
path: '/library/all/top',
queryParams: {
...(accountId && {accountId}),
@@ -36,7 +36,7 @@ const mostWatchedUrlParams = function(accountId, sectionKey, limit = 10) {
const getLibraryDataBySectionUrlParams = function(sectionId) {
return {
host: config.plex.plexServerUrl,
host: config.plex.plexUrl,
path: `/library/sections/${sectionId}/all`,
queryParams: {
'X-Plex-Token': config.plex.token,