2016-12-07 09:34:09 +00:00
|
|
|
package main
|
|
|
|
|
2017-05-11 13:04:43 +00:00
|
|
|
import (
|
2017-06-16 10:41:30 +00:00
|
|
|
//"log"
|
|
|
|
//"fmt"
|
2017-05-11 13:04:43 +00:00
|
|
|
"strconv"
|
|
|
|
"net"
|
|
|
|
"net/http"
|
|
|
|
"html"
|
|
|
|
"database/sql"
|
|
|
|
_ "github.com/go-sql-driver/mysql"
|
|
|
|
)
|
2016-12-07 09:34:09 +00:00
|
|
|
|
|
|
|
func route_edit_topic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("Bad Form",w,r)
|
2017-06-06 14:41:06 +00:00
|
|
|
return
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
is_js := r.PostFormValue("js")
|
|
|
|
if is_js == "" {
|
|
|
|
is_js = "0"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
var tid int
|
2016-12-07 09:34:09 +00:00
|
|
|
tid, err = strconv.Atoi(r.URL.Path[len("/topic/edit/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreErrorJSQ("The provided TopicID is not a valid number.",w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
old_topic, err := topics.CascadeGet(tid)
|
2017-01-31 05:13:38 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-10 13:39:13 +00:00
|
|
|
PreErrorJSQ("The topic you tried to edit doesn't exist.",w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,old_topic.ParentID)
|
2017-02-05 16:36:54 +00:00
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.EditTopic {
|
2017-01-31 05:13:38 +00:00
|
|
|
NoPermissionsJSQ(w,r,user,is_js)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
topic_name := r.PostFormValue("topic_name")
|
|
|
|
topic_status := r.PostFormValue("topic_status")
|
2017-01-12 02:55:08 +00:00
|
|
|
is_closed := (topic_status == "closed")
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
topic_content := html.EscapeString(r.PostFormValue("topic_content"))
|
2016-12-08 14:11:18 +00:00
|
|
|
_, err = edit_topic_stmt.Exec(topic_name, preparse_message(topic_content), parse_message(html.EscapeString(preparse_message(topic_content))), is_closed, tid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-02 13:00:40 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
if old_topic.Is_Closed != is_closed {
|
2017-04-02 13:00:40 +00:00
|
|
|
var action string
|
|
|
|
if is_closed {
|
|
|
|
action = "lock"
|
|
|
|
} else {
|
|
|
|
action = "unlock"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-05 14:05:37 +00:00
|
|
|
err = addModLog(action,tid,"topic",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-04-02 13:00:40 +00:00
|
|
|
_, err = create_action_reply_stmt.Exec(tid,action,ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-02 13:00:40 +00:00
|
|
|
_, err = add_replies_to_topic_stmt.Exec(1, tid)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = update_forum_cache_stmt.Exec(topic_name, tid, user.Name, user.ID, 1)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
err = topics.Load(tid)
|
2017-06-12 09:03:14 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-16 06:47:55 +00:00
|
|
|
LocalErrorJSQ("This topic no longer exists!",w,r,user,is_js)
|
2017-02-15 10:49:30 +00:00
|
|
|
return
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if err != nil {
|
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
|
|
|
return
|
2017-02-15 10:49:30 +00:00
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
if is_js == "0" {
|
2017-01-31 05:13:38 +00:00
|
|
|
http.Redirect(w,r,"/topic/" + strconv.Itoa(tid),http.StatusSeeOther)
|
2016-12-07 09:34:09 +00:00
|
|
|
} else {
|
2017-05-11 13:04:43 +00:00
|
|
|
w.Write(success_json_bytes)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func route_delete_topic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
tid, err := strconv.Atoi(r.URL.Path[len("/topic/delete/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The provided TopicID is not a valid number.",w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
topic, err := topics.CascadeGet(tid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The topic you tried to delete doesn't exist.",w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,topic.ParentID)
|
2017-02-05 16:36:54 +00:00
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.DeleteTopic {
|
2017-01-31 05:13:38 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = delete_topic_stmt.Exec(tid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-05 14:05:37 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("delete",tid,"topic",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
|
|
|
// Might need soft-delete before we can do an action reply for this
|
2017-04-05 14:05:37 +00:00
|
|
|
/*_, err = create_action_reply_stmt.Exec(tid,"delete",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}*/
|
2017-06-06 14:41:06 +00:00
|
|
|
|
|
|
|
//log.Print("Topic #" + strconv.Itoa(tid) + " was deleted by User #" + strconv.Itoa(user.ID))
|
2017-01-12 02:55:08 +00:00
|
|
|
http.Redirect(w,r,"/",http.StatusSeeOther)
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
wcount := word_count(topic.Content)
|
|
|
|
err = decrease_post_user_stats(wcount,topic.CreatedBy,true,user)
|
2017-01-12 02:55:08 +00:00
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2017-01-12 02:55:08 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
_, err = remove_topics_from_forum_stmt.Exec(1, topic.ParentID)
|
2017-01-26 13:37:50 +00:00
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2017-01-26 13:37:50 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-12 09:03:14 +00:00
|
|
|
forums[topic.ParentID].TopicCount -= 1
|
2017-02-15 10:49:30 +00:00
|
|
|
topics.Remove(tid)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_stick_topic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
tid, err := strconv.Atoi(r.URL.Path[len("/topic/stick/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The provided TopicID is not a valid number.",w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
topic, err := topics.CascadeGet(tid)
|
2017-01-31 05:13:38 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The topic you tried to pin doesn't exist.",w,r)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,topic.ParentID)
|
2017-02-05 16:36:54 +00:00
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.PinTopic {
|
2017-01-31 05:13:38 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = stick_topic_stmt.Exec(tid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("stick",tid,"topic",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = create_action_reply_stmt.Exec(tid,"stick",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-16 06:47:55 +00:00
|
|
|
err = topics.Load(tid)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("This topic doesn't exist!",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-02-04 06:19:55 +00:00
|
|
|
http.Redirect(w,r,"/topic/" + strconv.Itoa(tid),http.StatusSeeOther)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_unstick_topic(w http.ResponseWriter, r *http.Request) {
|
|
|
|
tid, err := strconv.Atoi(r.URL.Path[len("/topic/unstick/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The provided TopicID is not a valid number.",w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
topic, err := topics.CascadeGet(tid)
|
2017-01-31 05:13:38 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("The topic you tried to unpin doesn't exist.",w,r)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,topic.ParentID)
|
2017-02-05 16:36:54 +00:00
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.PinTopic {
|
2017-01-31 05:13:38 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = unstick_topic_stmt.Exec(tid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("unstick",tid,"topic",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = create_action_reply_stmt.Exec(tid,"unstick",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-16 06:47:55 +00:00
|
|
|
err = topics.Load(tid)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("This topic doesn't exist!",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-02-04 06:19:55 +00:00
|
|
|
http.Redirect(w,r,"/topic/" + strconv.Itoa(tid),http.StatusSeeOther)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_reply_edit_submit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("Bad Form",w,r)
|
2017-06-06 14:41:06 +00:00
|
|
|
return
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
is_js := r.PostFormValue("js")
|
|
|
|
if is_js == "" {
|
|
|
|
is_js = "0"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
rid, err := strconv.Atoi(r.URL.Path[len("/reply/edit/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
PreErrorJSQ("The provided Reply ID is not a valid number.",w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
content := html.EscapeString(preparse_message(r.PostFormValue("edit_item")))
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = edit_reply_stmt.Exec(content, parse_message(content), rid)
|
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
// Get the Reply ID..
|
|
|
|
var tid int
|
2017-06-06 14:41:06 +00:00
|
|
|
err = get_reply_tid_stmt.QueryRow(rid).Scan(&tid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-01-31 05:13:38 +00:00
|
|
|
var fid int
|
2017-06-06 14:41:06 +00:00
|
|
|
err = get_topic_fid_stmt.QueryRow(tid).Scan(&fid)
|
2017-01-31 05:13:38 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-10 13:39:13 +00:00
|
|
|
PreErrorJSQ("The parent topic doesn't exist.",w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,fid)
|
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.EditReply {
|
2017-02-10 13:39:13 +00:00
|
|
|
NoPermissionsJSQ(w,r,user,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
if is_js == "0" {
|
|
|
|
http.Redirect(w,r, "/topic/" + strconv.Itoa(tid) + "#reply-" + strconv.Itoa(rid), http.StatusSeeOther)
|
|
|
|
} else {
|
2017-05-11 13:04:43 +00:00
|
|
|
w.Write(success_json_bytes)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func route_reply_delete_submit(w http.ResponseWriter, r *http.Request) {
|
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreError("Bad Form",w,r)
|
2017-06-06 14:41:06 +00:00
|
|
|
return
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
is_js := r.PostFormValue("is_js")
|
|
|
|
if is_js == "" {
|
|
|
|
is_js = "0"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
rid, err := strconv.Atoi(r.URL.Path[len("/reply/delete/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreErrorJSQ("The provided Reply ID is not a valid number.",w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
reply, err := get_reply(rid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-05 16:36:54 +00:00
|
|
|
PreErrorJSQ("The reply you tried to delete doesn't exist.",w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-01-31 05:13:38 +00:00
|
|
|
var fid int
|
2017-06-14 07:09:44 +00:00
|
|
|
err = get_topic_fid_stmt.QueryRow(reply.ParentID).Scan(&fid)
|
2017-01-31 05:13:38 +00:00
|
|
|
if err == sql.ErrNoRows {
|
2017-02-10 13:39:13 +00:00
|
|
|
PreErrorJSQ("The parent topic doesn't exist.",w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-05 16:36:54 +00:00
|
|
|
user, ok := SimpleForumSessionCheck(w,r,fid)
|
|
|
|
if !ok {
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-02-05 16:36:54 +00:00
|
|
|
if !user.Perms.ViewTopic || !user.Perms.DeleteReply {
|
2017-02-10 13:39:13 +00:00
|
|
|
NoPermissionsJSQ(w,r,user,is_js)
|
2017-01-31 05:13:38 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = delete_reply_stmt.Exec(rid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
//log.Print("Reply #" + strconv.Itoa(rid) + " was deleted by User #" + strconv.Itoa(user.ID))
|
2016-12-07 09:34:09 +00:00
|
|
|
if is_js == "0" {
|
|
|
|
//http.Redirect(w,r, "/topic/" + strconv.Itoa(tid), http.StatusSeeOther)
|
|
|
|
} else {
|
2017-05-11 13:04:43 +00:00
|
|
|
w.Write(success_json_bytes)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
wcount := word_count(reply.Content)
|
|
|
|
err = decrease_post_user_stats(wcount, reply.CreatedBy, false, user)
|
2017-01-12 02:55:08 +00:00
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2017-01-12 02:55:08 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-14 07:09:44 +00:00
|
|
|
_, err = remove_replies_from_topic_stmt.Exec(1,reply.ParentID)
|
2017-01-21 18:16:27 +00:00
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2017-01-21 18:16:27 +00:00
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-14 07:09:44 +00:00
|
|
|
err = addModLog("delete",reply.ParentID,"reply",ipaddress,user.ID)
|
2017-04-06 17:37:32 +00:00
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-14 07:09:44 +00:00
|
|
|
err = topics.Load(reply.ParentID)
|
2017-02-15 10:49:30 +00:00
|
|
|
if err != nil {
|
|
|
|
LocalError("This topic no longer exists!",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_profile_reply_edit_submit(w http.ResponseWriter, r *http.Request) {
|
2016-12-16 10:37:42 +00:00
|
|
|
user, ok := SimpleSessionCheck(w,r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
LocalError("Bad Form",w,r,user)
|
2017-06-06 14:41:06 +00:00
|
|
|
return
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
is_js := r.PostFormValue("js")
|
|
|
|
if is_js == "" {
|
|
|
|
is_js = "0"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
rid, err := strconv.Atoi(r.URL.Path[len("/profile/reply/edit/submit/"):])
|
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
LocalErrorJSQ("The provided Reply ID is not a valid number.",w,r,user,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 13:46:14 +00:00
|
|
|
// Get the Reply ID..
|
|
|
|
var uid int
|
2017-06-06 14:41:06 +00:00
|
|
|
err = get_user_reply_uid_stmt.QueryRow(rid).Scan(&uid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-21 02:30:32 +00:00
|
|
|
if user.ID != uid && !user.Perms.EditReply {
|
2016-12-07 13:46:14 +00:00
|
|
|
NoPermissionsJSQ(w,r,user,is_js)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
content := html.EscapeString(preparse_message(r.PostFormValue("edit_item")))
|
2016-12-07 13:46:14 +00:00
|
|
|
_, err = edit_profile_reply_stmt.Exec(content, parse_message(content), rid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err != nil {
|
2017-02-10 13:39:13 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
if is_js == "0" {
|
2017-04-06 17:37:32 +00:00
|
|
|
http.Redirect(w,r,"/user/" + strconv.Itoa(uid) + "#reply-" + strconv.Itoa(rid), http.StatusSeeOther)
|
2016-12-07 09:34:09 +00:00
|
|
|
} else {
|
2017-05-11 13:04:43 +00:00
|
|
|
w.Write(success_json_bytes)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func route_profile_reply_delete_submit(w http.ResponseWriter, r *http.Request) {
|
2016-12-16 10:37:42 +00:00
|
|
|
user, ok := SimpleSessionCheck(w,r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
err := r.ParseForm()
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
LocalError("Bad Form",w,r,user)
|
2017-06-06 14:41:06 +00:00
|
|
|
return
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
is_js := r.PostFormValue("is_js")
|
|
|
|
if is_js == "" {
|
|
|
|
is_js = "0"
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
rid, err := strconv.Atoi(r.URL.Path[len("/profile/reply/delete/submit/"):])
|
|
|
|
if err != nil {
|
|
|
|
LocalErrorJSQ("The provided Reply ID is not a valid number.",w,r,user,is_js)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
var uid int
|
2017-06-06 14:41:06 +00:00
|
|
|
err = get_user_reply_uid_stmt.QueryRow(rid).Scan(&uid)
|
2016-12-07 09:34:09 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
LocalErrorJSQ("The reply you tried to delete doesn't exist.",w,r,user,is_js)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 13:46:14 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-21 02:30:32 +00:00
|
|
|
if user.ID != uid && !user.Perms.DeleteReply {
|
2016-12-07 13:46:14 +00:00
|
|
|
NoPermissionsJSQ(w,r,user,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
_, err = delete_profile_reply_stmt.Exec(rid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalErrorJSQ(err,w,r,is_js)
|
2016-12-07 09:34:09 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
//log.Print("The profile post '" + strconv.Itoa(rid) + "' was deleted by User #" + strconv.Itoa(user.ID))
|
|
|
|
|
2016-12-07 09:34:09 +00:00
|
|
|
if is_js == "0" {
|
|
|
|
//http.Redirect(w,r, "/user/" + strconv.Itoa(uid), http.StatusSeeOther)
|
|
|
|
} else {
|
2017-05-11 13:04:43 +00:00
|
|
|
w.Write(success_json_bytes)
|
2016-12-07 09:34:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
func route_ban(w http.ResponseWriter, r *http.Request) {
|
2017-06-16 10:41:30 +00:00
|
|
|
user, headerVars, ok := SessionCheck(w,r)
|
2016-12-16 10:37:42 +00:00
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2016-12-21 02:30:32 +00:00
|
|
|
if !user.Perms.BanUsers {
|
2016-12-08 14:11:18 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
uid, err := strconv.Atoi(r.URL.Path[len("/users/ban/"):])
|
|
|
|
if err != nil {
|
|
|
|
LocalError("The provided User ID is not a valid number.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
var uname string
|
2017-06-12 09:03:14 +00:00
|
|
|
err = get_user_name_stmt.QueryRow(uid).Scan(&uname)
|
2016-12-08 14:11:18 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
LocalError("The user you're trying to ban no longer exists.",w,r,user)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
confirm_msg := "Are you sure you want to ban '" + uname + "'?"
|
|
|
|
yousure := AreYouSure{"/users/ban/submit/" + strconv.Itoa(uid),confirm_msg}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-06-16 10:41:30 +00:00
|
|
|
pi := Page{"Ban User",user,headerVars,tList,yousure}
|
2017-02-04 06:19:55 +00:00
|
|
|
templates.ExecuteTemplate(w,"areyousure.html",pi)
|
2016-12-08 14:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_ban_submit(w http.ResponseWriter, r *http.Request) {
|
2016-12-16 10:37:42 +00:00
|
|
|
user, ok := SimpleSessionCheck(w,r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2016-12-21 02:30:32 +00:00
|
|
|
if !user.Perms.BanUsers {
|
2016-12-08 14:11:18 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if r.FormValue("session") != user.Session {
|
|
|
|
SecurityError(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
uid, err := strconv.Atoi(r.URL.Path[len("/users/ban/submit/"):])
|
|
|
|
if err != nil {
|
|
|
|
LocalError("The provided User ID is not a valid number.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-12 09:03:14 +00:00
|
|
|
/*if uid == -2 {
|
2017-04-06 17:37:32 +00:00
|
|
|
LocalError("Sigh, are you really trying to ban me? Do you despise so much? Despite all of our adventures over at /arcane-tower/...?",w,r,user)
|
|
|
|
return
|
2017-06-12 09:03:14 +00:00
|
|
|
}*/
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
var group int
|
|
|
|
var is_super_admin bool
|
2017-06-12 09:03:14 +00:00
|
|
|
err = get_user_rank_stmt.QueryRow(uid).Scan(&group, &is_super_admin)
|
2016-12-08 14:11:18 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
LocalError("The user you're trying to ban no longer exists.",w,r,user)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
if is_super_admin || groups[group].Is_Admin || groups[group].Is_Mod {
|
|
|
|
LocalError("You may not ban another staff member.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if uid == user.ID {
|
2017-04-06 17:37:32 +00:00
|
|
|
LocalError("Why are you trying to ban yourself? Stop that.",w,r,user)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
if groups[group].Is_Banned {
|
|
|
|
LocalError("The user you're trying to unban is already banned.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
_, err = change_group_stmt.Exec(4, uid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("ban",uid,"user",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
err = users.Load(uid)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("This user no longer exists!",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-04-06 17:37:32 +00:00
|
|
|
http.Redirect(w,r,"/user/" + strconv.Itoa(uid),http.StatusSeeOther)
|
2016-12-08 14:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func route_unban(w http.ResponseWriter, r *http.Request) {
|
2016-12-16 10:37:42 +00:00
|
|
|
user, ok := SimpleSessionCheck(w,r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2016-12-21 02:30:32 +00:00
|
|
|
if !user.Perms.BanUsers {
|
2016-12-08 14:11:18 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2016-12-23 12:35:22 +00:00
|
|
|
if r.FormValue("session") != user.Session {
|
|
|
|
SecurityError(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
uid, err := strconv.Atoi(r.URL.Path[len("/users/unban/"):])
|
|
|
|
if err != nil {
|
|
|
|
LocalError("The provided User ID is not a valid number.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
var group int
|
2017-06-12 09:03:14 +00:00
|
|
|
err = get_user_group_stmt.QueryRow(uid).Scan(&group)
|
2016-12-08 14:11:18 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
LocalError("The user you're trying to unban no longer exists.",w,r,user)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
if !groups[group].Is_Banned {
|
|
|
|
LocalError("The user you're trying to unban isn't banned.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-08 14:11:18 +00:00
|
|
|
_, err = change_group_stmt.Exec(default_group, uid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-08 14:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("unban",uid,"user",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
err = users.Load(uid)
|
2017-06-12 09:03:14 +00:00
|
|
|
if err != nil && err == sql.ErrNoRows {
|
2017-02-15 10:49:30 +00:00
|
|
|
LocalError("This user no longer exists!",w,r,user)
|
|
|
|
return
|
2017-06-12 09:03:14 +00:00
|
|
|
} else if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
2017-02-15 10:49:30 +00:00
|
|
|
}
|
2017-06-12 09:03:14 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
http.Redirect(w,r,"/user/" + strconv.Itoa(uid),http.StatusSeeOther)
|
2016-12-08 14:11:18 +00:00
|
|
|
}
|
|
|
|
|
2016-12-18 12:56:06 +00:00
|
|
|
func route_activate(w http.ResponseWriter, r *http.Request) {
|
|
|
|
user, ok := SimpleSessionCheck(w,r)
|
|
|
|
if !ok {
|
|
|
|
return
|
|
|
|
}
|
2016-12-21 02:30:32 +00:00
|
|
|
if !user.Perms.ActivateUsers {
|
2016-12-18 12:56:06 +00:00
|
|
|
NoPermissions(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2016-12-23 12:35:22 +00:00
|
|
|
if r.FormValue("session") != user.Session {
|
|
|
|
SecurityError(w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-18 12:56:06 +00:00
|
|
|
uid, err := strconv.Atoi(r.URL.Path[len("/users/activate/"):])
|
|
|
|
if err != nil {
|
|
|
|
LocalError("The provided User ID is not a valid number.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-18 12:56:06 +00:00
|
|
|
var active bool
|
2017-06-12 09:03:14 +00:00
|
|
|
err = get_user_active_stmt.QueryRow(uid).Scan(&active)
|
2016-12-18 12:56:06 +00:00
|
|
|
if err == sql.ErrNoRows {
|
|
|
|
LocalError("The account you're trying to activate no longer exists.",w,r,user)
|
|
|
|
return
|
|
|
|
} else if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-18 12:56:06 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-18 12:56:06 +00:00
|
|
|
if active {
|
|
|
|
LocalError("The account you're trying to activate has already been activated.",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
_, err = activate_user_stmt.Exec(uid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-18 12:56:06 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2016-12-21 02:30:32 +00:00
|
|
|
_, err = change_group_stmt.Exec(default_group, uid)
|
|
|
|
if err != nil {
|
2017-02-05 16:36:54 +00:00
|
|
|
InternalError(err,w,r)
|
2016-12-21 02:30:32 +00:00
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-04-06 17:37:32 +00:00
|
|
|
ipaddress, _, err := net.SplitHostPort(r.RemoteAddr)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("Bad IP",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
err = addModLog("activate",uid,"user",ipaddress,user.ID)
|
|
|
|
if err != nil {
|
|
|
|
InternalError(err,w,r)
|
|
|
|
return
|
|
|
|
}
|
2017-06-06 14:41:06 +00:00
|
|
|
|
2017-02-15 10:49:30 +00:00
|
|
|
err = users.Load(uid)
|
|
|
|
if err != nil {
|
|
|
|
LocalError("This user no longer exists!",w,r,user)
|
|
|
|
return
|
|
|
|
}
|
2017-04-06 17:37:32 +00:00
|
|
|
http.Redirect(w,r,"/user/" + strconv.Itoa(uid),http.StatusSeeOther)
|
2016-12-18 12:56:06 +00:00
|
|
|
}
|