Browse Source
Login app working (#47)
Login app working (#47)
Can login and create User object. Also now store user token info in db (closes #48).master
Kevin Mok
7 years ago
15 changed files with 224 additions and 194 deletions
-
16api/models.py
-
2api/urls.py
-
87api/utils.py
-
89api/views.py
-
1graphs/urls.py
-
22login/models.py
-
9login/templates/login/index.html
-
22login/templates/login/scan.html
-
3login/urls.py
-
132login/views.py
-
8recreate-db.txt
-
18reset_db.sh
-
3spotifyvis/settings.py
-
6spotifyvis/urls.py
-
0static/css/dark_bg.css
@ -0,0 +1,22 @@ |
|||||
|
from django.db import models |
||||
|
|
||||
|
# id's are 22 in length in examples but set to 30 for buffer |
||||
|
MAX_ID = 30 |
||||
|
# saw tokens being about ~150 chars in length |
||||
|
TOKEN_LENGTH = 200 |
||||
|
|
||||
|
class User(models.Model): |
||||
|
class Meta: |
||||
|
verbose_name = "User" |
||||
|
verbose_name_plural = "Users" |
||||
|
|
||||
|
# the user's Spotify ID |
||||
|
id = models.CharField(primary_key=True, max_length=MAX_ID) |
||||
|
secret = models.CharField(max_length=50, default='') |
||||
|
refresh_token = models.CharField(max_length=TOKEN_LENGTH) |
||||
|
access_token = models.CharField(max_length=TOKEN_LENGTH) |
||||
|
access_obtained_at = models.DateTimeField(auto_now_add=True) |
||||
|
access_expires_in = models.PositiveIntegerField() |
||||
|
|
||||
|
def __str__(self): |
||||
|
return self.user_id |
@ -0,0 +1,22 @@ |
|||||
|
{% load static %} |
||||
|
<!DOCTYPE html> |
||||
|
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> |
||||
|
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> |
||||
|
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> |
||||
|
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]--> |
||||
|
<head> |
||||
|
<meta charset="utf-8"> |
||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge"> |
||||
|
<title>User Spotify Data</title> |
||||
|
<meta name="description" content=""> |
||||
|
<meta name="viewport" content="width=device-width, initial-scale=1"> |
||||
|
<link rel="stylesheet" href="{% static 'css/dark_bg.css' %}"> |
||||
|
</head> |
||||
|
<body> |
||||
|
<!--[if lt IE 7]> |
||||
|
<p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="#">upgrade your browser</a> to improve your experience.</p> |
||||
|
<![endif]--> |
||||
|
<p>Logged in as {{ user_id }}</p> |
||||
|
<a href="" class="btn btn-primary">Scan Library</a> |
||||
|
</body> |
||||
|
</html> |
@ -1,8 +0,0 @@ |
|||||
# https://stackoverflow.com/a/34576062/8811872 |
|
||||
|
|
||||
sudo su postgres |
|
||||
psql |
|
||||
drop database spotifyvis; |
|
||||
create database spotifyvis with owner django; |
|
||||
\q |
|
||||
exit |
|
@ -1,14 +1,14 @@ |
|||||
# check if in virtual environment |
# check if in virtual environment |
||||
# https://stackoverflow.com/questions/15454174/how-can-a-shell-function-know-if-it-is-running-within-a-virtualenv/15454916 |
# https://stackoverflow.com/questions/15454174/how-can-a-shell-function-know-if-it-is-running-within-a-virtualenv/15454916 |
||||
|
|
||||
python -c 'import sys; print(sys.real_prefix)' 2>/dev/null && INVENV=1 || INVENV=0 |
|
||||
|
# python -c 'import sys; print(sys.real_prefix)' 2>/dev/null && INVENV=1 || INVENV=0 |
||||
|
# INVENV=$(python -c 'import sys; print ("1" if hasattr(sys, "real_prefix") else "0")') |
||||
|
|
||||
# echo $INVENV |
|
||||
# if $INVENV is 1, then in virtualenv |
# if $INVENV is 1, then in virtualenv |
||||
|
|
||||
if [ $INVENV -eq 1 ]; then |
|
||||
rm spotifyvis/migrations/00* |
|
||||
sudo -u postgres psql -f reset_db.sql |
|
||||
python manage.py makemigrations |
|
||||
python manage.py migrate |
|
||||
fi |
|
||||
|
# echo $INVENV |
||||
|
# if [ $INVENV -eq 1 ]; then |
||||
|
rm login/migrations/0* api/migrations/0* graphs/migrations/0* |
||||
|
sudo -u postgres psql -f reset_db.sql |
||||
|
python manage.py makemigrations |
||||
|
python manage.py migrate |
||||
|
# fi |
Write
Preview
Loading…
Cancel
Save
Reference in new issue