-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #88 from Pomog/yurii_dev
github login
- Loading branch information
Showing
52 changed files
with
3,599 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Go Forum Authenticate Web Application | ||
|
||
Go Forum Authentication is a vanilla Forum application with additional authentication methods. | ||
|
||
|
||
### Objectives | ||
|
||
The goal of this project is to implement, into your forum, new ways of authentication. You have to be able to register and to login using at least Google and Github authentication tools. | ||
|
||
Some examples of authentication means are: | ||
|
||
- GitHub | ||
|
||
### Instructions | ||
|
||
- To login with Google give contributors you Google e-mail to put your name on google whitelist. | ||
- Your project must have implemented at least the two authentication examples given. | ||
- Your project must be written in **Go**. | ||
- The code must respect the [**good practices**](../../good-practices/README.md). | ||
|
||
## Contributing | ||
|
||
- Kveber | ||
- Karl-Thomas | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package config | ||
|
||
import ( | ||
"database/sql" | ||
|
||
_ "github.com/mattn/go-sqlite3" | ||
) | ||
|
||
var DB *sql.DB | ||
|
||
func InitializeDB() (*sql.DB, error) { | ||
var err error | ||
DB, err = sql.Open("sqlite3", "mydb.db") | ||
return DB, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package config | ||
|
||
import ( | ||
"database/sql" | ||
"log" | ||
) | ||
|
||
func Run() { | ||
migrate(DB, UserTable) | ||
migrate(DB, PostTable) | ||
migrate(DB, CategoryTable) | ||
migrate(DB, PostCategoryTable) | ||
migrate(DB, PostRatingTable) | ||
migrate(DB, PostRepliesTable) | ||
migrate(DB, PostRepliesRatingTable) | ||
migrate(DB, SessionTable) | ||
} | ||
|
||
func migrate(db *sql.DB, query string) { | ||
statement, err := db.Prepare(query) | ||
if err == nil { | ||
_, creationError := statement.Exec() | ||
if creationError != nil { | ||
log.Println(creationError.Error()) | ||
} | ||
} else { | ||
log.Println(err.Error()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package config | ||
|
||
const UserTable = ` | ||
CREATE TABLE IF NOT EXISTS users ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
username TEXT NOT NULL UNIQUE, | ||
age INTEGER DEFAULT 0, | ||
gender TEXT, | ||
firstname TEXT, | ||
lastname TEXT, | ||
email TEXT NOT NULL UNIQUE, | ||
password TEXT NOT NULL, | ||
provider TEXT NOT NULL | ||
); | ||
` | ||
|
||
const PostTable = ` | ||
CREATE TABLE IF NOT EXISTS posts ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
title TEXT NOT NULL, | ||
content TEXT NOT NULL, | ||
created DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
user_id INTEGER, | ||
foreign key (user_id) REFERENCES users (id) | ||
); | ||
` | ||
|
||
const CategoryTable = ` | ||
CREATE TABLE IF NOT EXISTS categories ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT NOT NULL, | ||
name_slug TEXT NOT NULL | ||
); | ||
` | ||
|
||
const PostCategoryTable = ` | ||
CREATE TABLE IF NOT EXISTS posts_category ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
post_id INTEGER, | ||
category_id INTEGER, | ||
foreign key (post_id) REFERENCES posts (id), | ||
foreign key (category_id) REFERENCES categories (id) | ||
); | ||
` | ||
|
||
const PostRatingTable = ` | ||
CREATE TABLE IF NOT EXISTS posts_rating ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
post_id INTEGER, | ||
user_id INTEGER, | ||
rating INTEGER, | ||
foreign key (post_id) REFERENCES posts (id), | ||
foreign key (user_id) REFERENCES users (id) | ||
); | ||
` | ||
|
||
const PostRepliesTable = ` | ||
CREATE TABLE IF NOT EXISTS posts_replies ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
post_id INTEGER, | ||
user_id INTEGER, | ||
content TEXT, | ||
created DATETIME DEFAULT CURRENT_TIMESTAMP, | ||
foreign key (post_id) REFERENCES posts (id), | ||
foreign key (user_id) REFERENCES users (id) | ||
); | ||
` | ||
const PostRepliesRatingTable = ` | ||
CREATE TABLE IF NOT EXISTS posts_replies_rating ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
post_reply_id INTEGER, | ||
user_id INTEGER, | ||
rating INTEGER, | ||
foreign key (post_reply_id) REFERENCES posts_replies (id), | ||
foreign key (user_id) REFERENCES users (id) | ||
); | ||
` | ||
|
||
const SessionTable = ` | ||
CREATE TABLE IF NOT EXISTS sessions ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
user_id INTEGER, | ||
name TEXT, | ||
value TEXT, | ||
expiration DATETIME, | ||
foreign key (user_id) REFERENCES users (id) | ||
); | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package controller | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
|
||
"forum-authentication/types" | ||
) | ||
|
||
type CategoryController struct{} | ||
|
||
func (_ *CategoryController) CategoryController(w http.ResponseWriter, r *http.Request) { | ||
|
||
category_slug := r.URL.Query().Get("slug") | ||
|
||
if r.Method == "GET" { | ||
categories := []types.Categories{} | ||
var err error | ||
|
||
if category_slug == "" { | ||
categories, err = category.GetCategories() | ||
} else { | ||
categories, err = category.GetCategoryBySlug(category_slug) | ||
} | ||
|
||
if err != nil { | ||
fmt.Println(err) | ||
http.Error(w, "Error getting categories", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
categoriesJson, err := json.Marshal(categories) | ||
if err != nil { | ||
http.Error(w, "Error encoding JSON", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
w.WriteHeader(http.StatusAccepted) | ||
w.Write(categoriesJson) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package controller | ||
|
||
import ( | ||
"encoding/json" | ||
"html/template" | ||
"log" | ||
"net/http" | ||
) | ||
|
||
func RenderPage(w http.ResponseWriter, templatePath string, data interface{}) { | ||
tmpl, err := template.ParseGlob(templatePath) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
err = tmpl.Execute(w, data) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
func RespondWithJSON(w http.ResponseWriter, status int, data interface{}) { | ||
w.Header().Set("Content-Type", "application/json") | ||
w.WriteHeader(status) | ||
if err := json.NewEncoder(w).Encode(data); err != nil { | ||
http.Error(w, "Error with encoding response", http.StatusInternalServerError) | ||
} | ||
} |
Oops, something went wrong.