@ -6,6 +6,7 @@ package routes
import (
"net/mail"
"net/http"
"os"
"os/exec"
"path/filepath"
@ -186,7 +187,7 @@ func InstallPost(c *context.Context, f form.Install) {
}
if _ , err := exec . LookPath ( "git" ) ; err != nil {
c . RenderWithErr ( c . Tr ( "install.test_git_failed" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.test_git_failed" , err ) , INSTALL , & f , http . StatusOK )
return
}
@ -203,7 +204,7 @@ func InstallPost(c *context.Context, f form.Install) {
if models . DbCfg . Type == "sqlite3" && len ( models . DbCfg . Path ) == 0 {
c . FormErr ( "DbPath" )
c . RenderWithErr ( c . Tr ( "install.err_empty_db_path" ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.err_empty_db_path" ) , INSTALL , & f , http . StatusBadRequest )
return
}
@ -212,10 +213,10 @@ func InstallPost(c *context.Context, f form.Install) {
if err := models . NewTestEngine ( x ) ; err != nil {
if strings . Contains ( err . Error ( ) , ` Unknown database type: sqlite3 ` ) {
c . FormErr ( "DbType" )
c . RenderWithErr ( c . Tr ( "install.sqlite3_not_available" , "https://gogs.io/docs/installation/install_from_binary.html" ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.sqlite3_not_available" , "https://gogs.io/docs/installation/install_from_binary.html" ) , INSTALL , & f , http . StatusOK )
} else {
c . FormErr ( "DbSetting" )
c . RenderWithErr ( c . Tr ( "install.invalid_db_setting" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.invalid_db_setting" , err ) , INSTALL , & f , http . StatusOK )
}
return
}
@ -224,7 +225,7 @@ func InstallPost(c *context.Context, f form.Install) {
f . RepoRootPath = strings . Replace ( f . RepoRootPath , "\\" , "/" , - 1 )
if err := os . MkdirAll ( f . RepoRootPath , os . ModePerm ) ; err != nil {
c . FormErr ( "RepoRootPath" )
c . RenderWithErr ( c . Tr ( "install.invalid_repo_path" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.invalid_repo_path" , err ) , INSTALL , & f , http . StatusOK )
return
}
@ -232,21 +233,21 @@ func InstallPost(c *context.Context, f form.Install) {
f . LogRootPath = strings . Replace ( f . LogRootPath , "\\" , "/" , - 1 )
if err := os . MkdirAll ( f . LogRootPath , os . ModePerm ) ; err != nil {
c . FormErr ( "LogRootPath" )
c . RenderWithErr ( c . Tr ( "install.invalid_log_root_path" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.invalid_log_root_path" , err ) , INSTALL , & f , http . StatusOK )
return
}
currentUser , match := setting . IsRunUserMatchCurrentUser ( f . RunUser )
if ! match {
c . FormErr ( "RunUser" )
c . RenderWithErr ( c . Tr ( "install.run_user_not_match" , f . RunUser , currentUser ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.run_user_not_match" , f . RunUser , currentUser ) , INSTALL , & f , http . StatusOK )
return
}
// Check host address and port
if len ( f . SMTPHost ) > 0 && ! strings . Contains ( f . SMTPHost , ":" ) {
c . FormErr ( "SMTP" , "SMTPHost" )
c . RenderWithErr ( c . Tr ( "install.smtp_host_missing_port" ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.smtp_host_missing_port" ) , INSTALL , & f , http . StatusOK )
return
}
@ -255,7 +256,7 @@ func InstallPost(c *context.Context, f form.Install) {
_ , err := mail . ParseAddress ( f . SMTPFrom )
if err != nil {
c . FormErr ( "SMTP" , "SMTPFrom" )
c . RenderWithErr ( c . Tr ( "install.invalid_smtp_from" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.invalid_smtp_from" , err ) , INSTALL , & f , http . StatusOK )
return
}
}
@ -263,19 +264,19 @@ func InstallPost(c *context.Context, f form.Install) {
// Check logic loophole between disable self-registration and no admin account.
if f . DisableRegistration && len ( f . AdminName ) == 0 {
c . FormErr ( "Services" , "Admin" )
c . RenderWithErr ( c . Tr ( "install.no_admin_and_disable_registration" ) , INSTALL , f )
c . RenderWithErr ( c . Tr ( "install.no_admin_and_disable_registration" ) , INSTALL , f , http . StatusOK )
return
}
// Check admin password.
if len ( f . AdminName ) > 0 && len ( f . AdminPasswd ) == 0 {
c . FormErr ( "Admin" , "AdminPasswd" )
c . RenderWithErr ( c . Tr ( "install.err_empty_admin_password" ) , INSTALL , f )
c . RenderWithErr ( c . Tr ( "install.err_empty_admin_password" ) , INSTALL , f , http . StatusOK )
return
}
if f . AdminPasswd != f . AdminConfirmPasswd {
c . FormErr ( "Admin" , "AdminPasswd" )
c . RenderWithErr ( c . Tr ( "form.password_not_match" ) , INSTALL , f )
c . RenderWithErr ( c . Tr ( "form.password_not_match" ) , INSTALL , f , http . StatusOK )
return
}
@ -348,14 +349,14 @@ func InstallPost(c *context.Context, f form.Install) {
cfg . Section ( "security" ) . Key ( "INSTALL_LOCK" ) . SetValue ( "true" )
secretKey , err := tool . RandomString ( 15 )
if err != nil {
c . RenderWithErr ( c . Tr ( "install.secret_key_failed" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.secret_key_failed" , err ) , INSTALL , & f , http . StatusInternalServerError )
return
}
cfg . Section ( "security" ) . Key ( "SECRET_KEY" ) . SetValue ( secretKey )
os . MkdirAll ( filepath . Dir ( setting . CustomConf ) , os . ModePerm )
if err := cfg . SaveTo ( setting . CustomConf ) ; err != nil {
c . RenderWithErr ( c . Tr ( "install.save_config_failed" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.save_config_failed" , err ) , INSTALL , & f , http . StatusInternalServerError )
return
}
@ -374,7 +375,7 @@ func InstallPost(c *context.Context, f form.Install) {
if ! models . IsErrUserAlreadyExist ( err ) {
setting . InstallLock = false
c . FormErr ( "AdminName" , "AdminEmail" )
c . RenderWithErr ( c . Tr ( "install.invalid_admin_setting" , err ) , INSTALL , & f )
c . RenderWithErr ( c . Tr ( "install.invalid_admin_setting" , err ) , INSTALL , & f , http . StatusBadRequest )
return
}
log . Info ( "Admin account already exist" )