Skip to content

Commit

Permalink
Fix signup template, fix new report page access
Browse files Browse the repository at this point in the history
  • Loading branch information
terrazoon committed May 14, 2017
1 parent c1c7731 commit ee6148c
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 70 deletions.
49 changes: 34 additions & 15 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
from model import *
from google.appengine.ext import db

#TODO
# move global methods to a utils.py file
# move handles to new package
# refactor post/user db model stuff using: https://cloud.google.com/appengine/articles/modeling#one-to-many.
# write a better readme with this: https://www.udacity.com/course/writing-readmes--ud777

template_dir = os.path.join(os.path.dirname(__file__), 'templates')
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),
autoescape = True)
Expand Down Expand Up @@ -191,25 +197,38 @@ def get(self):
# Handles a new post
class NewPostHandler(Handler):
def get(self):
hsh = self.request.cookies.get('username')
if not valid_cookie(hsh):
self.redirect('/signup')

arr = hsh.split("|")
username = arr[0]
if username=='':
self.redirect('/signup')
self.render('newpost.html')

def post(self):
self.write("post")
hsh = self.request.cookies.get('username')
if valid_cookie(hsh):
arr = hsh.split("|")
username = arr[0]
subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
newpost = BlogPost(author=username, subject=subject,
content=content, likes=0)
newpost.put()
self.redirect('/blog/%s' % str(newpost.key().id()))
else:
self.redirect('/blog/newpost')
else:
if not valid_cookie(hsh):
self.redirect('/signup')



arr = hsh.split("|")
username = arr[0]
if username == '':
self.redirect('/signup')

subject = self.request.get('subject')
content = self.request.get('content')
if subject and content:
newpost = BlogPost(author=username, subject=subject,
content=content, likes=0)
newpost.put()
self.redirect('/blog/%s' % str(newpost.key().id()))
else:
self.redirect('/blog/newpost')

# Handles a permalink after new post is saved
class PermalinkHandler(Handler):
def get(self, post_id):
Expand Down
Binary file modified main.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ a {
color: red;
}

.error {
.success {
color: #099900;
}

Expand Down
70 changes: 16 additions & 54 deletions templates/signup.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,61 +2,23 @@

{% block content %}


<h2>Signup</h2>
<form method="post">
<table>
<tr>
<td class="label">
Username
</td>
<td>
<input type="text" name="username" value="{{username}}">
</td>
<td class="error">
{{error_username}}
</td>
</tr>

<tr>
<td class="label">
Password
</td>
<td>
<input type="password" name="password" value="">
</td>
<td class="error">
{{error_password}}
</td>
</tr>

<tr>
<td class="label">
Verify Password
</td>
<td>
<input type="password" name="verify" value="">
</td>
<td class="error">
{{error_verify}}
</td>
</tr>

<tr>
<td class="label">
Email (optional)
</td>
<td>
<input type="text" name="email" value="">
</td>
<td class="error">
{{error_email}}
</td>
</tr>
</table>

<input type="submit">
</form>
<form method="post">
<fieldset>
<legend>Signup:</legend>
User name:<br>
<input type="text" name="username" value="{{username}}"><div class="error">{{error_username}}</div><br>
Password:<br>
<input type="password" name="password" value=""><div class="error">{{error_password}}</div><br>
Verify password:<br>
<input type="password" name="verify" value=""><div class="error">{{error_verify}}</div><br>
Email (optional):<br>
<input type="text" name="email" value=""><div class="error">{{error_email}}</div><br><br>

<input type="submit" value="Submit">
</fieldset>
</form>


<form method="get" action="/login">
<button class="logout" type="submit">Login</button>
Expand Down

0 comments on commit ee6148c

Please sign in to comment.