preference apply; user signup bug fix

This commit is contained in:
Liang Ding 2014-11-20 11:17:43 +08:00
parent 7218eef212
commit 24908aa309
1 changed files with 9 additions and 0 deletions

View File

@ -23,6 +23,7 @@ import (
"runtime"
"strconv"
"text/template"
"sync"
"github.com/b3log/wide/conf"
"github.com/b3log/wide/i18n"
@ -36,6 +37,9 @@ const (
UserCreateError = "user create error"
)
// Exclusive lock for adding user.
var addUserMutex sync.Mutex
// PreferenceHandle handles request of preference page.
func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
httpSession, _ := HTTPSession.Get(r, "wide-session")
@ -106,6 +110,8 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
user.Password = args.Password
user.Locale = args.Locale
conf.UpdateCustomizedConf(username)
succ = conf.Save()
}
@ -241,6 +247,9 @@ func SignUpUser(w http.ResponseWriter, r *http.Request) {
// 3. update the user customized configurations, such as style.css
// 4. serve files of the user's workspace via HTTP
func addUser(username, password string) string {
addUserMutex.Lock()
defer addUserMutex.Unlock()
for _, user := range conf.Wide.Users {
if user.Name == username {
return UserExists