add user email 📧
This commit is contained in:
parent
86cf85d24e
commit
332213e3cf
|
@ -57,6 +57,7 @@ type LatestSessionContent struct {
|
|||
type User struct {
|
||||
Name string
|
||||
Password string
|
||||
Email string
|
||||
Workspace string // the GOPATH of this user
|
||||
Locale string
|
||||
GoFormat string
|
||||
|
@ -67,9 +68,9 @@ type User struct {
|
|||
LatestSessionContent *LatestSessionContent
|
||||
}
|
||||
|
||||
// NewUser creates a user with the specified username, password and workspace.
|
||||
func NewUser(username, password, workspace string) *User {
|
||||
return &User{Name: username, Password: password, Workspace: workspace,
|
||||
// NewUser creates a user with the specified username, password, email and workspace.
|
||||
func NewUser(username, password, email, workspace string) *User {
|
||||
return &User{Name: username, Password: password, Email: email, Workspace: workspace,
|
||||
Locale: Wide.Locale, GoFormat: "gofmt", FontFamily: "Helvetica", FontSize: "13px", Theme: "default",
|
||||
Editor: &Editor{FontFamily: "Consolas, 'Courier New', monospace", FontSize: "inherit", Theme: "wide",
|
||||
TabSize: "4"}}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
{
|
||||
"Name": "admin",
|
||||
"Password": "admin",
|
||||
"Email": "",
|
||||
"Workspace": "${GOPATH}",
|
||||
"Locale": "en_US",
|
||||
"GoFormat": "gofmt",
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
"team": "Team",
|
||||
"sing_up_error": "Sign Up Error",
|
||||
"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",
|
||||
"discard": "Discard",
|
||||
"close": "Close",
|
||||
|
@ -154,5 +155,6 @@
|
|||
"select_identifier": "Select Identifier",
|
||||
"source": "Source",
|
||||
"toggle_comment": "Toggle Comment",
|
||||
"find_in_files": "Find in Files"
|
||||
"find_in_files": "Find in Files",
|
||||
"email": "Email"
|
||||
}
|
|
@ -118,6 +118,7 @@
|
|||
"team": "チーム",
|
||||
"sing_up_error": "登録に失敗しました",
|
||||
"user_name_ruler": "16の長さからなる_ AZ、AZ、0-9、によってユーザ名のみ",
|
||||
"invalid_email": "無効な電子メール",
|
||||
"password_no_match": "一貫性のないパスワード入力",
|
||||
"discard": "あきらめる",
|
||||
"close": "クローズ",
|
||||
|
@ -154,5 +155,6 @@
|
|||
"select_identifier": "選択識別子",
|
||||
"source": "ソース",
|
||||
"toggle_comment": "トグルコメント",
|
||||
"find_in_files": "ファイルから検索"
|
||||
"find_in_files": "ファイルから検索",
|
||||
"email": "Eメール"
|
||||
}
|
||||
|
|
|
@ -118,6 +118,7 @@
|
|||
"team": "团队",
|
||||
"sing_up_error": "注册失败",
|
||||
"user_name_ruler": "用户名只能由 a-z, A-Z, 0-9, _ 组成,长度为16",
|
||||
"invalid_email": "无效的电子邮件",
|
||||
"password_no_match": "密码输入不一致",
|
||||
"discard": "放弃",
|
||||
"close": "关闭",
|
||||
|
@ -154,5 +155,6 @@
|
|||
"select_identifier": "选择标识符",
|
||||
"source": "源码",
|
||||
"toggle_comment": "注释",
|
||||
"find_in_files": "在文件中查找"
|
||||
"find_in_files": "在文件中查找",
|
||||
"email": "电子邮件"
|
||||
}
|
|
@ -118,6 +118,7 @@
|
|||
"team": "團隊",
|
||||
"sing_up_error": "註冊失敗",
|
||||
"user_name_ruler": "用戶名只能由az, AZ, 0-9, _ 組成,長度為16",
|
||||
"invalid_email": "無效的電子郵件",
|
||||
"password_no_match": "密碼輸入不一致",
|
||||
"discard": "放棄",
|
||||
"close": "關閉",
|
||||
|
@ -154,5 +155,6 @@
|
|||
"select_identifier": "選擇標識符",
|
||||
"source": "源代碼",
|
||||
"toggle_comment": "註釋",
|
||||
"find_in_files": "在文件中查找"
|
||||
"find_in_files": "在文件中查找",
|
||||
"email": "電子郵件"
|
||||
}
|
|
@ -32,7 +32,10 @@ import (
|
|||
)
|
||||
|
||||
const (
|
||||
// TODO: i18n
|
||||
|
||||
userExists = "user exists"
|
||||
emailExists = "email exists"
|
||||
userCreated = "user created"
|
||||
userCreateError = "user create error"
|
||||
)
|
||||
|
@ -89,6 +92,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
Workspace string
|
||||
Username string
|
||||
Password string
|
||||
Email string
|
||||
Locale string
|
||||
Theme string
|
||||
EditorFontFamily string
|
||||
|
@ -110,6 +114,7 @@ func PreferenceHandler(w http.ResponseWriter, r *http.Request) {
|
|||
user.GoFormat = args.GoFmt
|
||||
user.Workspace = args.Workspace
|
||||
user.Password = args.Password
|
||||
user.Email = args.Email
|
||||
user.Locale = args.Locale
|
||||
user.Theme = args.Theme
|
||||
user.Editor.FontFamily = args.EditorFontFamily
|
||||
|
@ -240,21 +245,22 @@ func SignUpUser(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
username := args["username"].(string)
|
||||
password := args["password"].(string)
|
||||
email := args["email"].(string)
|
||||
|
||||
msg := addUser(username, password)
|
||||
msg := addUser(username, password, email)
|
||||
if userCreated != msg {
|
||||
succ = false
|
||||
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
|
||||
// 2. generate 'Hello, 世界' demo code in the workspace
|
||||
// 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 {
|
||||
func addUser(username, password, email string) string {
|
||||
addUserMutex.Lock()
|
||||
defer addUserMutex.Unlock()
|
||||
|
||||
|
@ -262,13 +268,17 @@ func addUser(username, password string) string {
|
|||
if user.Name == username {
|
||||
return userExists
|
||||
}
|
||||
|
||||
if user.Email == email {
|
||||
return emailExists
|
||||
}
|
||||
}
|
||||
|
||||
firstUserWorkspace := conf.Wide.GetUserWorkspace(conf.Wide.Users[0].Name)
|
||||
dir := filepath.Dir(firstUserWorkspace)
|
||||
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)
|
||||
|
||||
if !conf.Save() {
|
||||
|
|
|
@ -155,7 +155,7 @@
|
|||
}
|
||||
|
||||
.form.sign-up {
|
||||
margin-top: -71px;
|
||||
margin-top: -108px;
|
||||
}
|
||||
|
||||
#signUpBtn {
|
||||
|
|
|
@ -364,6 +364,7 @@ var menu = {
|
|||
$goFmt = $dialogPreference.find("input[name=goFmt]"),
|
||||
$workspace = $dialogPreference.find("input[name=workspace]"),
|
||||
$password = $dialogPreference.find("input[name=password]"),
|
||||
$email = $dialogPreference.find("input[name=email]"),
|
||||
$locale = $dialogPreference.find("input[name=locale]"),
|
||||
$theme = $dialogPreference.find("input[name=theme]"),
|
||||
$editorFontFamily = $dialogPreference.find("input[name=editorFontFamily]"),
|
||||
|
@ -378,6 +379,7 @@ var menu = {
|
|||
"goFmt": $goFmt.val(),
|
||||
"workspace": $workspace.val(),
|
||||
"password": $password.val(),
|
||||
"email": $email.val(),
|
||||
"locale": $locale.val(),
|
||||
"theme": $theme.val(),
|
||||
"editorFontFamily": $editorFontFamily.val(),
|
||||
|
@ -401,6 +403,7 @@ var menu = {
|
|||
$goFmt.data("value", $goFmt.val());
|
||||
$workspace.data("value", $workspace.val());
|
||||
$password.data("value", $password.val());
|
||||
$email.data("value", $email.val());
|
||||
$locale.data("value", $locale.val());
|
||||
$theme.data("value", $theme.val());
|
||||
$editorFontFamily.data("value", $editorFontFamily.val());
|
||||
|
|
|
@ -88,6 +88,10 @@
|
|||
</select>
|
||||
<br/>
|
||||
</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" />
|
||||
<label>
|
||||
{{.i18n.workspace}}{{.i18n.colon}}
|
||||
|
|
|
@ -34,6 +34,7 @@
|
|||
<div id="dir" data-dir="{{.dir}}{{.pathSeparator}}">{{.dir}}{{.pathSeparator}}</div>
|
||||
</div>
|
||||
<input id="username" placeholder="Username"/><br/>
|
||||
<input id="email" placeholder="Email"/><br/>
|
||||
<input id="password" type="password" placeholder="Password"/><br/>
|
||||
<input id="confirmPassword" type="password" placeholder="Confirm your password"/>
|
||||
<button id="signUpBtn" class="button">{{.i18n.sign_up}}</button>
|
||||
|
@ -60,6 +61,10 @@
|
|||
$("#msg").text("{{.i18n.user_name_ruler}}").show();
|
||||
$("#username").focus();
|
||||
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()) === "") {
|
||||
$("#msg").text("{{.i18n.sing_up_error}}").show();
|
||||
$("#password").focus();
|
||||
|
@ -72,7 +77,8 @@
|
|||
|
||||
var request = {
|
||||
username: $("#username").val(),
|
||||
password: $("#password").val()
|
||||
password: $("#password").val(),
|
||||
email: $("#email").val()
|
||||
};
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
|
@ -97,7 +103,7 @@
|
|||
|| $.trim($(this).val()).length > 16) {
|
||||
$("#msg").text("{{.i18n.user_name_ruler}}").show();
|
||||
} else {
|
||||
$("#password").focus();
|
||||
$("#email").focus();
|
||||
$("#msg").hide();
|
||||
}
|
||||
} else {
|
||||
|
@ -112,6 +118,18 @@
|
|||
}
|
||||
}).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) {
|
||||
if (event.which === 13) {
|
||||
if ($.trim($(this).val()) === "") {
|
||||
|
|
Loading…
Reference in New Issue