Commit 6882e79a authored by ras19's avatar ras19
Browse files

Recreated tables and database, both for development and production [RS, IK, EW]

parent 6c854874
Pipeline #203529 passed with stages
in 2 minutes and 40 seconds
......@@ -13,7 +13,7 @@ def get_all_users():
user_query = User.query.all()
users_list = [{"firstname" : x.firstname, "surname" : x.surname,
"title" : x.title, "email" : x.email, "bio" : x.bio, "joined" : x.joined,
"title" : x.title, "email" : x.email, "phone_no" : x.phone_no, "bio" : x.bio, "joined" : x.joined,
"location" : x.location, "availability" : x.availability,
"partnership_opportunities" : x.partnership_opportunities,
"interests" : x.interests, "username" : x.username } for x in user_query]
......@@ -36,6 +36,7 @@ def get_id(username):
password = user.password,
title = user.title,
email = user.email,
phone_no = user.phone_no,
bio = user.bio,
joined = user.joined,
location = user.location,
......@@ -47,19 +48,19 @@ def get_id(username):
@user.route('/users', methods=['POST'])
def add_user():
username, firstname, surname, password, title, email, bio, joined, location, availability, partnership_opportunities, interests = (
username, firstname, surname, password, title, email, phone_no, bio, joined, location, availability, partnership_opportunities, interests = (
request.json['username'], request.json['firstname'],
request.json['surname'],
request.json['password'],
request.json['title'],
request.json['email'], request.json['bio'], request.json['joined'],
request.json['email'], request.json['phone_no'], request.json['bio'], request.json['joined'],
request.json['location'],request.json['availability'],
request.json['partnership_opportunities'], request.json['interests'])
salt = bcrypt.gensalt()
hash_pswd = bcrypt.hashpw(password.encode('utf-8'), salt).decode('utf-8')
entry = User(username = username, firstname = firstname, surname = surname, password = hash_pswd,
title = title, email = email, bio = bio, joined = joined, location = location,
title = title, email = email, phone_no = phone_no, bio = bio, joined = joined, location = location,
availability = availability, partnership_opportunities = partnership_opportunities,
interests = interests)
DB.add(entry)
......@@ -69,12 +70,12 @@ def add_user():
@user.route('/users/<username>', methods=['POST'])
def update_user(username):
entry = User.query.get(username)
firstname, surname, password, title, email, bio, joined, location, availability, partnership_opportunities, interests = (
firstname, surname, password, title, email, phone_no, bio, joined, location, availability, partnership_opportunities, interests = (
request.json['firstname'],
request.json['surname'],
request.json['password'],
request.json['title'],
request.json['email'], request.json['bio'], request.json['joined'],
request.json['email'], request.json['phone_no'], request.json['bio'], request.json['joined'],
request.json['location'],request.json['availability'],
request.json['partnership_opportunities'], request.json['interests'])
entry.firstname = firstname
......@@ -87,6 +88,7 @@ def update_user(username):
entry.title = title
entry.email = email
entry.phone_no = phone_no
entry.bio = bio
entry.joined = joined
entry.location = location
......
......@@ -26,7 +26,7 @@ app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
if ENV == 'dev':
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://g205001034_u:CierkbZMND@db.doc.ic.ac.uk:5432/g205001034_u'
else:
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://icbwsbzlctcxyx:a0d7f73e5b743a35f33d95640b517b6e7e9e5b59cd2ff10673e90372b4b34d44@ec2-34-193-112-164.compute-1.amazonaws.com:5432/deje5qriuvrh39'
app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://ozufqkgtnoptrc:42b722a2bf88caa314bc0558abb0098d0971a9d588728a64413576cd62255003@ec2-54-224-120-186.compute-1.amazonaws.com:5432/dfbpe6718mqdmh'
# Mail settings for "forgot password" mail sending
mail_settings = {
......
"""empty message
Revision ID: 0bf2570a97ff
Revises: f5d42d08aad0
Create Date: 2021-06-16 08:13:15.381027
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '0bf2570a97ff'
down_revision = 'f5d42d08aad0'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=False)
op.create_foreign_key(None, 'assigned_tasks', 'task', ['task_id'], ['id'])
op.create_foreign_key(None, 'assigned_tasks', 'user', ['username'], ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=True)
# ### end Alembic commands ###
"""empty message
Revision ID: 3cf62eb96987
Revises: b784652933b7
Create Date: 2021-06-16 07:53:30.916792
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = '3cf62eb96987'
down_revision = 'b784652933b7'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=False)
op.create_foreign_key(None, 'assigned_tasks', 'user', ['username'], ['username'])
op.create_foreign_key(None, 'assigned_tasks', 'task', ['task_id'], ['id'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=True)
# ### end Alembic commands ###
"""empty message
Revision ID: b784652933b7
Revision ID: cd2b194a323c
Revises:
Create Date: 2021-06-13 18:29:25.146966
Create Date: 2021-06-16 16:56:23.129198
"""
from alembic import op
......@@ -10,7 +10,7 @@ import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'b784652933b7'
revision = 'cd2b194a323c'
down_revision = None
branch_labels = None
depends_on = None
......@@ -18,12 +18,6 @@ depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('assigned_tasks',
sa.Column('task_id', sa.Integer(), nullable=True),
sa.Column('username', sa.String(), nullable=True),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.PrimaryKeyConstraint('id')
)
op.create_table('project',
sa.Column('name', sa.String(), nullable=True),
sa.Column('status', sa.String(), nullable=True),
......@@ -40,8 +34,9 @@ def upgrade():
sa.Column('password', sa.String(), nullable=True),
sa.Column('title', sa.String(), nullable=True),
sa.Column('email', sa.String(), nullable=True),
sa.Column('phone_no', sa.String(), nullable=True),
sa.Column('bio', sa.String(), nullable=True),
sa.Column('joined', sa.String(), nullable=True),
sa.Column('joined', sa.Date(), nullable=True),
sa.Column('location', sa.String(), nullable=True),
sa.Column('availability', sa.String(), nullable=True),
sa.Column('partnership_opportunities', sa.String(), nullable=True),
......@@ -76,15 +71,23 @@ def upgrade():
sa.ForeignKeyConstraint(['username'], ['user.username'], ),
sa.PrimaryKeyConstraint('id')
)
op.create_table('assigned_task',
sa.Column('task_id', sa.Integer(), nullable=False),
sa.Column('username', sa.String(), nullable=False),
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
sa.ForeignKeyConstraint(['task_id'], ['task.id'], ),
sa.ForeignKeyConstraint(['username'], ['user.username'], ),
sa.PrimaryKeyConstraint('id')
)
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('assigned_task')
op.drop_table('user_project')
op.drop_table('todo')
op.drop_table('task')
op.drop_table('user')
op.drop_table('project')
op.drop_table('assigned_tasks')
# ### end Alembic commands ###
"""empty message
Revision ID: f5d42d08aad0
Revises: 3cf62eb96987
Create Date: 2021-06-16 08:11:57.508998
"""
from alembic import op
import sqlalchemy as sa
# revision identifiers, used by Alembic.
revision = 'f5d42d08aad0'
down_revision = '3cf62eb96987'
branch_labels = None
depends_on = None
def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=False)
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=False)
op.create_foreign_key(None, 'assigned_tasks', 'task', ['task_id'], ['id'])
op.create_foreign_key(None, 'assigned_tasks', 'user', ['username'], ['username'])
# ### end Alembic commands ###
def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.drop_constraint(None, 'assigned_tasks', type_='foreignkey')
op.alter_column('assigned_tasks', 'username',
existing_type=sa.VARCHAR(),
nullable=True)
op.alter_column('assigned_tasks', 'task_id',
existing_type=sa.INTEGER(),
nullable=True)
# ### end Alembic commands ###
{
"files": {
"main.css": "/static/react/css/main.5e2a6a72.chunk.css",
"main.js": "/static/react/js/main.4f2a1e71.chunk.js",
"main.js.map": "/static/react/js/main.4f2a1e71.chunk.js.map",
"main.js": "/static/react/js/main.04e205b1.chunk.js",
"main.js.map": "/static/react/js/main.04e205b1.chunk.js.map",
"runtime-main.js": "/static/react/js/runtime-main.094287be.js",
"runtime-main.js.map": "/static/react/js/runtime-main.094287be.js.map",
"js/2.c5f15404.chunk.js": "/static/react/js/2.c5f15404.chunk.js",
"js/2.c5f15404.chunk.js.map": "/static/react/js/2.c5f15404.chunk.js.map",
"js/2.f51a0a11.chunk.js": "/static/react/js/2.f51a0a11.chunk.js",
"js/2.f51a0a11.chunk.js.map": "/static/react/js/2.f51a0a11.chunk.js.map",
"js/3.ddc4d6e7.chunk.js": "/static/react/js/3.ddc4d6e7.chunk.js",
"js/3.ddc4d6e7.chunk.js.map": "/static/react/js/3.ddc4d6e7.chunk.js.map",
"../../templates/index.html": "/static/react/../../templates/index.html",
"css/main.5e2a6a72.chunk.css.map": "/static/react/css/main.5e2a6a72.chunk.css.map",
"js/2.c5f15404.chunk.js.LICENSE.txt": "/static/react/js/2.c5f15404.chunk.js.LICENSE.txt"
"js/2.f51a0a11.chunk.js.LICENSE.txt": "/static/react/js/2.f51a0a11.chunk.js.LICENSE.txt"
},
"entrypoints": [
"js/runtime-main.094287be.js",
"js/2.c5f15404.chunk.js",
"js/2.f51a0a11.chunk.js",
"css/main.5e2a6a72.chunk.css",
"js/main.4f2a1e71.chunk.js"
"js/main.04e205b1.chunk.js"
]
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/react/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/react/logo192.png"/><link rel="manifest" href="/static/react/manifest.json"/><title>React App</title><script>window.token="{{DRP_token}}"</script><link href="/static/react/css/main.5e2a6a72.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,u,i=r[0],c=r[1],l=r[2],s=0,p=[];s<i.length;s++)u=i[s],Object.prototype.hasOwnProperty.call(o,u)&&o[u]&&p.push(o[u][0]),o[u]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return a.push.apply(a,l||[]),t()}function t(){for(var e,r=0;r<a.length;r++){for(var t=a[r],n=!0,i=1;i<t.length;i++){var c=t[i];0!==o[c]&&(n=!1)}n&&(a.splice(r--,1),e=u(u.s=t[0]))}return e}var n={},o={1:0},a=[];function u(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,u),t.l=!0,t.exports}u.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var a,i=document.createElement("script");i.charset="utf-8",i.timeout=120,u.nc&&i.setAttribute("nonce",u.nc),i.src=function(e){return u.p+"js/"+({}[e]||e)+"."+{3:"ddc4d6e7"}[e]+".chunk.js"}(e);var c=new Error;a=function(r){i.onerror=i.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+a+")",c.name="ChunkLoadError",c.type=n,c.request=a,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){a({type:"timeout",target:i})}),12e4);i.onerror=i.onload=a,document.head.appendChild(i)}return Promise.all(r)},u.m=e,u.c=n,u.d=function(e,r,t){u.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},u.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,r){if(1&r&&(e=u(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(u.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)u.d(t,n,function(r){return e[r]}.bind(null,n));return t},u.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(r,"a",r),r},u.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},u.p="/static/react/",u.oe=function(e){throw console.error(e),e};var i=this["webpackJsonpinaglobe-dashboard"]=this["webpackJsonpinaglobe-dashboard"]||[],c=i.push.bind(i);i.push=r,i=i.slice();for(var l=0;l<i.length;l++)r(i[l]);var f=c;t()}([])</script><script src="/static/react/js/2.c5f15404.chunk.js"></script><script src="/static/react/js/main.4f2a1e71.chunk.js"></script></body></html>
\ No newline at end of file
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/react/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/react/logo192.png"/><link rel="manifest" href="/static/react/manifest.json"/><title>React App</title><script>window.token="{{DRP_token}}"</script><link href="/static/react/css/main.5e2a6a72.chunk.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,u,i=r[0],c=r[1],l=r[2],s=0,p=[];s<i.length;s++)u=i[s],Object.prototype.hasOwnProperty.call(o,u)&&o[u]&&p.push(o[u][0]),o[u]=0;for(n in c)Object.prototype.hasOwnProperty.call(c,n)&&(e[n]=c[n]);for(f&&f(r);p.length;)p.shift()();return a.push.apply(a,l||[]),t()}function t(){for(var e,r=0;r<a.length;r++){for(var t=a[r],n=!0,i=1;i<t.length;i++){var c=t[i];0!==o[c]&&(n=!1)}n&&(a.splice(r--,1),e=u(u.s=t[0]))}return e}var n={},o={1:0},a=[];function u(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,u),t.l=!0,t.exports}u.e=function(e){var r=[],t=o[e];if(0!==t)if(t)r.push(t[2]);else{var n=new Promise((function(r,n){t=o[e]=[r,n]}));r.push(t[2]=n);var a,i=document.createElement("script");i.charset="utf-8",i.timeout=120,u.nc&&i.setAttribute("nonce",u.nc),i.src=function(e){return u.p+"js/"+({}[e]||e)+"."+{3:"ddc4d6e7"}[e]+".chunk.js"}(e);var c=new Error;a=function(r){i.onerror=i.onload=null,clearTimeout(l);var t=o[e];if(0!==t){if(t){var n=r&&("load"===r.type?"missing":r.type),a=r&&r.target&&r.target.src;c.message="Loading chunk "+e+" failed.\n("+n+": "+a+")",c.name="ChunkLoadError",c.type=n,c.request=a,t[1](c)}o[e]=void 0}};var l=setTimeout((function(){a({type:"timeout",target:i})}),12e4);i.onerror=i.onload=a,document.head.appendChild(i)}return Promise.all(r)},u.m=e,u.c=n,u.d=function(e,r,t){u.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},u.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},u.t=function(e,r){if(1&r&&(e=u(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(u.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)u.d(t,n,function(r){return e[r]}.bind(null,n));return t},u.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return u.d(r,"a",r),r},u.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},u.p="/static/react/",u.oe=function(e){throw console.error(e),e};var i=this["webpackJsonpinaglobe-dashboard"]=this["webpackJsonpinaglobe-dashboard"]||[],c=i.push.bind(i);i.push=r,i=i.slice();for(var l=0;l<i.length;l++)r(i[l]);var f=c;t()}([])</script><script src="/static/react/js/2.f51a0a11.chunk.js"></script><script src="/static/react/js/main.04e205b1.chunk.js"></script></body></html>
\ No newline at end of file
import { useState } from "react";
import { useHistory } from "react-router-dom"
const AddUser = () => {
const [firstname, setFirstname] = useState("");
const [surname, setSurname] = useState("");
const [password, setPassword] = useState("");
const [title, setTitle] = useState("")
const [email, setEmail] = useState("");
const [phone_no, setPhoneNo] = useState("");
const [bio, setBio] = useState("");
const [joined, setJoined] = useState("");
const [joined, setJoined] = useState(Date.now());
const [location, setLocation] = useState("");
const [availability, setAvailability] = useState("");
const [partnership_opportunities, setPartnership_opportunities] = useState("");
const [interests, setInterests] = useState("");
const [username, setUsername] = useState("");
const history = useHistory();
const handleSubmit = e => {
......@@ -29,6 +27,7 @@ const AddUser = () => {
password,
title,
email,
phone_no,
bio,
joined,
location,
......@@ -106,6 +105,14 @@ const AddUser = () => {
placeholder="Input InAGlobe email here"
/>
<label>Phone Number</label>
<input
type="text"
value={phone_no}
onChange={(e) => setPhoneNo(e.target.value)}
placeholder="Input your phone number"
/>
<label>Bio</label>
<input
......@@ -116,9 +123,10 @@ const AddUser = () => {
/>
{/* Think about changing type to force date */}
<label>Joined</label>
<label>Joined [required]</label>
<input
type="text"
type="date"
required
value={joined}
onChange={(e) => setJoined(e.target.value)}
placeholder="Eg: 20th April 2020"
......
......@@ -4,8 +4,8 @@ import useFetch from './useFetch'
const EditUser = () => {
const { username } = useParams();
const { data: {firstname, surname, password, title, email, bio, joined,
location, availability, partnership_opportunities, interests}, error, isPending } = useFetch("/users/" + username)
const { data: { firstname, surname, password, title, email, phone_no, bio, joined,
location, availability, partnership_opportunities, interests }, error, isPending } = useFetch("/users/" + username)
const history = useHistory();
const oldUserDetails = {
......@@ -14,6 +14,7 @@ const EditUser = () => {
password: password,
title: title,
email: email,
phone_no: phone_no,
bio: bio,
joined: joined,
location: location,
......@@ -21,7 +22,7 @@ const EditUser = () => {
partnership_opportunities: partnership_opportunities,
interests: interests,
}
const { register, handleSubmit } = useForm({
defaultValues: oldUserDetails
});
......@@ -39,9 +40,9 @@ const EditUser = () => {
return (
<div className="edit-user">
<h2>Edit user</h2>
{ isPending && <h2>Loading...</h2> }
{isPending && <h2>Loading...</h2>}
<Link to={`/users/change-password`}>Change Password</Link>
{ firstname && <form onSubmit={handleSubmit(onSubmit)}>
{firstname && <form onSubmit={handleSubmit(onSubmit)}>
<label htmlFor="firstname">Firstname</label>
<input {...register("firstname")}
placeholder="Input your first name here"
......@@ -67,6 +68,11 @@ const EditUser = () => {
placeholder="Input InAGlobe email here"
/>
<label htmlFor="phone_no">Phone number</label>
<input {...register("phone_no")}
placeholder="Input phone number here"
/>
<label htmlFor="bio">Bio</label>
<input {...register("bio")}
......@@ -100,7 +106,7 @@ const EditUser = () => {
placeholder="What are your hobbies?"
/>
<button type="submit">Save user details</button>
</form> }
</form>}
</div>
);
}
......
......@@ -11,7 +11,7 @@ const Users = () => {
return (
<div className="users">
<h1>Users</h1>
{ <Link to={`/add-user`} className="add-user-button">Add User</Link> }
{ token == "jaimeaguilera" && <Link to={`/add-user`} className="add-user-button">Add User</Link> }
<br />
<br />
{ isPending && <h2>Loading...</h2> }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment