Skip to content

Commit

Permalink
lots of fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed Dec 8, 2019
1 parent 2017daa commit c125657
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 59 deletions.
31 changes: 20 additions & 11 deletions main.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ pub mut:
cur_user User
}

pub fn (app mut App) reset() {
app.cur_user = User{}
}


fn main() {
println('Running vorum on http://localhost:$port')
mut app := App{}
Expand All @@ -41,32 +46,35 @@ pub fn (app mut App) index() {

// TODO ['/post/:id/:title']
// TODO `fn (app App) post(id int)`
pub fn (app &App) post() {
pub fn (app mut App) post() {
id := app.get_post_id()
post := app.retrieve_post(id) or {
app.vweb.redirect('/')
return
}
app.auth()
comments := app.find_comments(id)
show_form := true
show_form := app.cur_user.name != ''
$vweb.html()
}

// new post
pub fn (app &App) new() {
pub fn (app mut App) new() {
app.auth()
logged_in := app.cur_user.name != ''
$vweb.html()
}

// [post]
pub fn (app & App) new_post() {
pub fn (app mut App) new_post() {
app.auth()
mut name := ''
if app.cur_user.name != '' {
name = app.cur_user.name
}
else {
} else {
// not logged in
//return
name = 'admin' // TODO remove
app.vweb.redirect('/new')
return
}
title := app.vweb.form['title']
mut text := app.vweb.form['text']
Expand All @@ -83,16 +91,17 @@ pub fn (app & App) new_post() {
}

// [post]
fn (app & App) comment() {
fn (app mut App) comment() {
app.auth()
post_id := app.get_post_id()
mut name := ''// b.form['name']
if app.cur_user.name != '' {
name = app.cur_user.name
}
else {
// not logged in
//return
name = 'admin' // TODO remove
app.vweb.redirect('/')
return
}
mut comment_text := app.vweb.form['text']
if name == '' || comment_text == '' {
Expand Down
41 changes: 23 additions & 18 deletions new.html
Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
@header

<div class='center'>
<form action='/new_post' method='post'>
<input type=text required minlength=4 name=title placeholder='Title'>
<textarea name='text' required minlength=10 placeholder='Write your post here'></textarea>
<input type='submit' value='Post'>
</form>
</div>

<div class='sep' style='border:0'></div>

<div class='center'>

<div class='sep' style='border:0'></div>

@if logged_in
<div class='center'>
<form action='/new_post' method='post'>
<input type=text required minlength=4 name=title placeholder='Title'>
<textarea name='text' required minlength=10 placeholder='Write your post here'></textarea>
<input type='submit' value='Post'>
</form>
</div>

@else

<div class='center'>
<a href='https://github.com/login/oauth/authorize?response_type=code&client_id=@CLIENT_ID'
>Log in via GitHub to create a new topic</a>
</div>
>Log in via GitHub to create a new topic</a>
</div>

@end

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>



64 changes: 34 additions & 30 deletions post.html
Original file line number Diff line number Diff line change
@@ -1,50 +1,54 @@
@header

<h1>@post.title</h1>
<h1>@post.title</h1>

<div class="sep" style="border:0"></div>
<div class="sep" style="border:0"></div>

<div class="center">
<div class="center">

@for comment in comments
<div class=comment>
<b>@comment.name</b> <i>@comment.time</i>
<div class=text>@comment.text</div>
</div>
@end
</div>
@end


@if show_form
<form method="post" action="/comment/@post.id/title">
<textarea name="text" required minlength=3
placeholder="Write your comment here"></textarea>
<input type="submit" value="Post">
</form>
@end
@if show_form
<form method="post" action="/comment/@post.id/title">
<textarea name="text" required minlength=3
placeholder="Write your comment here"></textarea>
<input type="submit" value="Post">
</form>
@end


</div>
</div>

<div class="sep" style="border:0;"></div>
<div class="sep" style="border:0;"></div>

<div class="center">
@if !show_form

<div class="center">
<a href="https://github.com/login/oauth/authorize?response_type=code&client_id=@CLIENT_ID"
>Log in via GitHub to comment</a>
</div>

<div class="center">
<!-- beautiful layout -->
<br>
<br>
<br>

>Log in via GitHub to comment</a>
</div>

@end

<div class="center">
<!-- beautiful layout -->
<br>
<br>
<br>

<center style="color:#777">
Powered by <a target=_blank href="https://github.com/vlang/vorum">vorum</a>,
Powered by <a target=_blank href="https://github.com/vlang/vorum">vorum</a>,
open-source blogging/forum software written in V
</center>
<br>
<br>
</div>
</center>

<br>
<br>
</div>


0 comments on commit c125657

Please sign in to comment.