Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change login system to discord oauth #2

Draft
wants to merge 2 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
*.db
*.sql
main
nyaa
nyaa.exe
nyaa-master.exe
mogupantsu
mogupantsu.exe
mogupantsu-master.exe
*.zip
*.swp
.idea
Expand All @@ -16,6 +16,7 @@ templates/*.html.go
tags
*.retry
config/config.yml
Godeps/_workspace

# emacs temp files
*\#*
Expand Down
11 changes: 5 additions & 6 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const (
// User model
type User struct {
ID uint `gorm:"column:user_id;primary_key"`
Username string `gorm:"column:username;unique"`
Username string `gorm:"column:username"`
Password string `gorm:"column:password"`
Email string `gorm:"column:email;unique"`
Status int `gorm:"column:status"`
Expand All @@ -47,7 +47,7 @@ type User struct {
Language string `gorm:"column:language"`
Theme string `gorm:"column:theme"`
AltColors string `gorm:"column:alt_colors"`
OldNav string `gorm:"column:old_nav"`
OldNav string `gorm:"column:old_nav"`
Mascot string `gorm:"column:mascot"`
MascotURL string `gorm:"column:mascot_url"`
AnidexAPIToken string `gorm:"column:anidex_api_token"`
Expand Down Expand Up @@ -170,7 +170,6 @@ func (u *User) ToggleBan() bool {
return u.IsBanned()
}


// CurrentOrAdmin check that user has admin permission or user is the current user.
func (u *User) CurrentOrAdmin(userID uint) bool {
if userID == 0 && !u.IsModerator() {
Expand All @@ -179,6 +178,7 @@ func (u *User) CurrentOrAdmin(userID uint) bool {
log.Debugf("user.ID == userID %d %d %t", u.ID, userID, u.ID == userID)
return (u.IsModerator() || u.ID == userID)
}

// CurrentOrJanitor check that user has janitor permission or user is the current user.
func (u *User) CurrentOrJanitor(userID uint) bool {
if userID == 0 && !u.IsJanitor() {
Expand Down Expand Up @@ -217,7 +217,7 @@ func (u *User) CanUpload() bool {
// GetRole : Get the status/role of a user
func (u *User) GetRole() string {
if u.ID == 0 {
return ""
return ""
}
switch u.Status {
case UserStatusBanned:
Expand All @@ -243,7 +243,6 @@ func (follower *User) IsFollower(userid uint) bool {
return likingUserCount != 0
}


// ToJSON : Conversion of a user model to json
func (u *User) ToJSON() UserJSON {
json := UserJSON{
Expand Down Expand Up @@ -291,7 +290,7 @@ func (u *User) RemoveFollow(follower *User) {
ORM.Delete(&userFollows)
for i, followr := range u.Likings {
if followr.ID == follower.ID {
u.Likings[i] = u.Likings[len(u.Likings)-1]
u.Likings[i] = u.Likings[len(u.Likings)-1]
// The very last follower will take the place of the one that is getting deleted in the array
u.Likings = u.Likings[:len(u.Likings)-1]
// We now proceed to delete the very last array element since it got copied to another position
Expand Down