add user email 📧

This commit is contained in:
Liang Ding 2014-12-08 14:02:39 +08:00
parent 86cf85d24e
commit 332213e3cf
11 changed files with 59 additions and 14 deletions

View File

@ -57,6 +57,7 @@ type LatestSessionContent struct {
type User struct { type User struct {
Name string Name string
Password string Password string
Email string
Workspace string // the GOPATH of this user Workspace string // the GOPATH of this user
Locale string Locale string
GoFormat string GoFormat string
@ -67,9 +68,9 @@ type User struct {
LatestSessionContent *LatestSessionContent LatestSessionContent *LatestSessionContent
} }
// NewUser creates a user with the specified username, password and workspace. // NewUser creates a user with the specified username, password, email and workspace.
func NewUser(username, password, workspace string) *User { func NewUser(username, password, email, workspace string) *User {
return &User{Name: username, Password: password, Workspace: workspace, return &User{Name: username, Password: password, Email: email, Workspace: workspace,
Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default", Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
Editor: &Editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", Theme: "wide", Editor: &Editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", Theme: "wide",
TabSize: "4"}} TabSize: "4"}}

View File

@ -17,6 +17,7 @@
{ {
"Name": "admin", "Name": "admin",
"Password": "admin", "Password": "admin",
"Email": "",
"Workspace": "${GOPATH}", "Workspace": "${GOPATH}",
"Locale": "en_US", "Locale": "en_US",
"GoFormat": "gofmt", "GoFormat": "gofmt",

View File

@ -118,6 +118,7 @@
"team": "Team", "team": "Team",
"sing_up_error": "Sign Up Error", "sing_up_error": "Sign Up Error",
"user_name_ruler": "Username only by az, AZ, 0-9, _ consisting of a length of 16", "user_name_ruler": "Username only by az, AZ, 0-9, _ consisting of a length of 16",
"invalid_email": "Invalid Email",
"password_no_match": "Password doesn't match the confirmation", "password_no_match": "Password doesn't match the confirmation",
"discard": "Discard", "discard": "Discard",
"close": "Close", "close": "Close",
@ -154,5 +155,6 @@
"select_identifier": "Select Identifier", "select_identifier": "Select Identifier",
"source": "Source", "source": "Source",
"toggle_comment": "Toggle Comment", "toggle_comment": "Toggle Comment",
"find_in_files": "Find in Files" "find_in_files": "Find in Files",
"email": "Email"
} }

View File

@ -118,6 +118,7 @@
"team": "チーム", "team": "チーム",
"sing_up_error": "登録に失敗しました", "sing_up_error": "登録に失敗しました",
"user_name_ruler": "16の長さからなる_ AZ、AZ、0-9、によってユーザ名のみ", "user_name_ruler": "16の長さからなる_ AZ、AZ、0-9、によってユーザ名のみ",
"invalid_email": "無効な電子メール",
"password_no_match": "一貫性のないパスワード入力", "password_no_match": "一貫性のないパスワード入力",
"discard": "あきらめる", "discard": "あきらめる",
"close": "クローズ", "close": "クローズ",
@ -154,5 +155,6 @@
"select_identifier": "選択識別子", "select_identifier": "選択識別子",
"source": "ソース", "source": "ソース",
"toggle_comment": "トグルコメント", "toggle_comment": "トグルコメント",
"find_in_files": "ファイルから検索" "find_in_files": "ファイルから検索",
"email": "Eメール"
} }

View File

@ -118,6 +118,7 @@
"team": "团队", "team": "团队",
"sing_up_error": "注册失败", "sing_up_error": "注册失败",
"user_name_ruler": "用户名只能由 a-z, A-Z, 0-9, _ 组成长度为16", "user_name_ruler": "用户名只能由 a-z, A-Z, 0-9, _ 组成长度为16",
"invalid_email": "无效的电子邮件",
"password_no_match": "密码输入不一致", "password_no_match": "密码输入不一致",
"discard": "放弃", "discard": "放弃",
"close": "关闭", "close": "关闭",
@ -154,5 +155,6 @@
"select_identifier": "选择标识符", "select_identifier": "选择标识符",
"source": "源码", "source": "源码",
"toggle_comment": "注释", "toggle_comment": "注释",
"find_in_files": "在文件中查找" "find_in_files": "在文件中查找",
"email": "电子邮件"
} }

View File

@ -118,6 +118,7 @@
"team": "團隊", "team": "團隊",
"sing_up_error": "註冊失敗", "sing_up_error": "註冊失敗",
"user_name_ruler": "用戶名只能由az, AZ, 0-9, _ 組成長度為16", "user_name_ruler": "用戶名只能由az, AZ, 0-9, _ 組成長度為16",
"invalid_email": "無效的電子郵件",
"password_no_match": "密碼輸入不一致", "password_no_match": "密碼輸入不一致",
"discard": "放棄", "discard": "放棄",
"close": "關閉", "close": "關閉",
@ -154,5 +155,6 @@
"select_identifier": "選擇標識符", "select_identifier": "選擇標識符",
"source": "源代碼", "source": "源代碼",
"toggle_comment": "註釋", "toggle_comment": "註釋",
"find_in_files": "在文件中查找" "find_in_files": "在文件中查找",
"email": "電子郵件"
} }

View File

@ -32,7 +32,10 @@ import (
) )
const ( const (
// TODO: i18n
userExists = "user exists" userExists = "user exists"
emailExists = "email exists"
userCreated = "user created" userCreated = "user created"
userCreateError = "user create error" userCreateError = "user create error"
) )
@ -89,6 +92,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
Workspace string Workspace string
Username string Username string
Password string Password string
Email string
Locale string Locale string
Theme string Theme string
EditorFontFamily string EditorFontFamily string
@ -110,6 +114,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
user.GoFormat = args.GoFmt user.GoFormat = args.GoFmt
user.Workspace = args.Workspace user.Workspace = args.Workspace
user.Password = args.Password user.Password = args.Password
user.Email = args.Email
user.Locale = args.Locale user.Locale = args.Locale
user.Theme = args.Theme user.Theme = args.Theme
user.Editor.FontFamily = args.EditorFontFamily user.Editor.FontFamily = args.EditorFontFamily
@ -240,21 +245,22 @@ func SignUpUser(w http.ResponseWriter, r *http.Request) {
username := args["username"].(string) username := args["username"].(string)
password := args["password"].(string) password := args["password"].(string)
email := args["email"].(string)
msg := addUser(username, password) msg := addUser(username, password, email)
if userCreated != msg { if userCreated != msg {
succ = false succ = false
data["msg"] = msg data["msg"] = msg
} }
} }
// addUser add a user with the specified username and password. // addUser add a user with the specified username, password and email.
// //
// 1. create the user's workspace // 1. create the user's workspace
// 2. generate 'Hello, 世界' demo code in the workspace // 2. generate 'Hello, 世界' demo code in the workspace
// 3. update the user customized configurations, such as style.css // 3. update the user customized configurations, such as style.css
// 4. serve files of the user's workspace via HTTP // 4. serve files of the user's workspace via HTTP
func addUser(username, password string) string { func addUser(username, password, email string) string {
addUserMutex.Lock() addUserMutex.Lock()
defer addUserMutex.Unlock() defer addUserMutex.Unlock()
@ -262,13 +268,17 @@ func addUser(username, password string) string {
if user.Name == username { if user.Name == username {
return userExists return userExists
} }
if user.Email == email {
return emailExists
}
} }
firstUserWorkspace := conf.Wide.GetUserWorkspace(conf.Wide.Users[0].Name) firstUserWorkspace := conf.Wide.GetUserWorkspace(conf.Wide.Users[0].Name)
dir := filepath.Dir(firstUserWorkspace) dir := filepath.Dir(firstUserWorkspace)
workspace := filepath.Join(dir, username) workspace := filepath.Join(dir, username)
newUser := conf.NewUser(username, password, workspace) newUser := conf.NewUser(username, password, email, workspace)
conf.Wide.Users = append(conf.Wide.Users, newUser) conf.Wide.Users = append(conf.Wide.Users, newUser)
if !conf.Save() { if !conf.Save() {

View File

@ -155,7 +155,7 @@
} }
.form.sign-up { .form.sign-up {
margin-top: -71px; margin-top: -108px;
} }
#signUpBtn { #signUpBtn {

View File

@ -364,6 +364,7 @@ var menu = {
$goFmt = $dialogPreference.find("input[name=goFmt]"), $goFmt = $dialogPreference.find("input[name=goFmt]"),
$workspace = $dialogPreference.find("input[name=workspace]"), $workspace = $dialogPreference.find("input[name=workspace]"),
$password = $dialogPreference.find("input[name=password]"), $password = $dialogPreference.find("input[name=password]"),
$email = $dialogPreference.find("input[name=email]"),
$locale = $dialogPreference.find("input[name=locale]"), $locale = $dialogPreference.find("input[name=locale]"),
$theme = $dialogPreference.find("input[name=theme]"), $theme = $dialogPreference.find("input[name=theme]"),
$editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"), $editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"),
@ -378,6 +379,7 @@ var menu = {
"goFmt": $goFmt.val(), "goFmt": $goFmt.val(),
"workspace": $workspace.val(), "workspace": $workspace.val(),
"password": $password.val(), "password": $password.val(),
"email": $email.val(),
"locale": $locale.val(), "locale": $locale.val(),
"theme": $theme.val(), "theme": $theme.val(),
"editorFontFamily": $editorFontFamily.val(), "editorFontFamily": $editorFontFamily.val(),
@ -401,6 +403,7 @@ var menu = {
$goFmt.data("value", $goFmt.val()); $goFmt.data("value", $goFmt.val());
$workspace.data("value", $workspace.val()); $workspace.data("value", $workspace.val());
$password.data("value", $password.val()); $password.data("value", $password.val());
$email.data("value", $email.val());
$locale.data("value", $locale.val()); $locale.data("value", $locale.val());
$theme.data("value", $theme.val()); $theme.data("value", $theme.val());
$editorFontFamily.data("value", $editorFontFamily.val()); $editorFontFamily.data("value", $editorFontFamily.val());

View File

@ -88,6 +88,10 @@
</select> </select>
<br/> <br/>
</label> </label>
<label>
{{.i18n.email}}{{.i18n.colon}}
<input data-value="{{.user.Email}}" value="{{.user.Email}}" name="email"/>
</label>
<input data-value="{{.user.Locale}}" value="{{.user.Locale}}" name="locale" hidden="hidden" /> <input data-value="{{.user.Locale}}" value="{{.user.Locale}}" name="locale" hidden="hidden" />
<label> <label>
{{.i18n.workspace}}{{.i18n.colon}} {{.i18n.workspace}}{{.i18n.colon}}

View File

@ -34,6 +34,7 @@
<div id="dir" data-dir="{{.dir}}{{.pathSeparator}}">{{.dir}}{{.pathSeparator}}</div> <div id="dir" data-dir="{{.dir}}{{.pathSeparator}}">{{.dir}}{{.pathSeparator}}</div>
</div> </div>
<input id="username" placeholder="Username"/><br/> <input id="username" placeholder="Username"/><br/>
<input id="email" placeholder="Email"/><br/>
<input id="password" type="password" placeholder="Password"/><br/> <input id="password" type="password" placeholder="Password"/><br/>
<input id="confirmPassword" type="password" placeholder="Confirm your password"/> <input id="confirmPassword" type="password" placeholder="Confirm your password"/>
<button id="signUpBtn" class="button">{{.i18n.sign_up}}</button> <button id="signUpBtn" class="button">{{.i18n.sign_up}}</button>
@ -60,6 +61,10 @@
$("#msg").text("{{.i18n.user_name_ruler}}").show(); $("#msg").text("{{.i18n.user_name_ruler}}").show();
$("#username").focus(); $("#username").focus();
return false; return false;
} else if (!/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i.test($("#email").val())) {
$("#msg").text("{{.i18n.invalid_email}}").show();
$("#email").focus();
return false;
} else if ($.trim($("#password").val()) === "") { } else if ($.trim($("#password").val()) === "") {
$("#msg").text("{{.i18n.sing_up_error}}").show(); $("#msg").text("{{.i18n.sing_up_error}}").show();
$("#password").focus(); $("#password").focus();
@ -72,7 +77,8 @@
var request = { var request = {
username: $("#username").val(), username: $("#username").val(),
password: $("#password").val() password: $("#password").val(),
email: $("#email").val()
}; };
$.ajax({ $.ajax({
type: 'POST', type: 'POST',
@ -97,7 +103,7 @@
|| $.trim($(this).val()).length > 16) { || $.trim($(this).val()).length > 16) {
$("#msg").text("{{.i18n.user_name_ruler}}").show(); $("#msg").text("{{.i18n.user_name_ruler}}").show();
} else { } else {
$("#password").focus(); $("#email").focus();
$("#msg").hide(); $("#msg").hide();
} }
} else { } else {
@ -112,6 +118,18 @@
} }
}).focus(); }).focus();
$("#email").keydown(function (event) {
if (event.which === 13) {
if ($.trim($(this).val()) === "") {
$("#msg").text("{{.i18n.invalid_email}}").show();
} else {
$("#password").focus();
}
} else {
$("#msg").hide();
}
});
$("#password").keydown(function (event) { $("#password").keydown(function (event) {
if (event.which === 13) { if (event.which === 13) {
if ($.trim($(this).val()) === "") { if ($.trim($(this).val()) === "") {