Add postgres support, clean code, code review
This commit is contained in:
@ -11,11 +11,12 @@ github.com/Unknwon/cae=
|
|||||||
github.com/Unknwon/goconfig=
|
github.com/Unknwon/goconfig=
|
||||||
github.com/dchest/scrypt=
|
github.com/dchest/scrypt=
|
||||||
github.com/go-sql-driver/mysql=
|
github.com/go-sql-driver/mysql=
|
||||||
|
github.com/lib/pq=
|
||||||
github.com/lunny/xorm=
|
github.com/lunny/xorm=
|
||||||
github.com/slene/blackfriday=
|
|
||||||
github.com/gogits/logs=
|
github.com/gogits/logs=
|
||||||
github.com/gogits/binding=
|
github.com/gogits/binding=
|
||||||
github.com/gogits/git=
|
github.com/gogits/git=
|
||||||
|
github.com/gogits/gfm=
|
||||||
|
|
||||||
[res]
|
[res]
|
||||||
include=templates|public|conf
|
include=templates|public|conf
|
||||||
|
@ -13,7 +13,8 @@ There are some very good products in this category such as [gitlab](http://gitla
|
|||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, develop specification, change log and road map.
|
- Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, develop specification, change log and road map.
|
||||||
|
- See [Trello Broad](https://trello.com/b/uxAoeLUl/gogs-go-git-service) to follow the develop team.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
@ -24,6 +25,7 @@ Please see [Wiki](https://github.com/gogits/gogs/wiki) for project design, devel
|
|||||||
- User profile page.
|
- User profile page.
|
||||||
- Repository viewer.
|
- Repository viewer.
|
||||||
- Gravatar support.
|
- Gravatar support.
|
||||||
|
- Supports MySQL and PostgreSQL.
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
@ -40,4 +42,4 @@ There are two ways to install Gogs:
|
|||||||
|
|
||||||
## Contributors
|
## Contributors
|
||||||
|
|
||||||
This project was launched by [Unknown](https://github.com/Unknwon), [lunny](https://github.com/lunny) and [fuxiaohei](https://github.com/fuxiaohei). See [contributors page](https://github.com/gogits/gogs/graphs/contributors) for full list of contributors.
|
This project was launched by [Unknown](https://github.com/Unknwon) and [lunny](https://github.com/lunny); [fuxiaohei](https://github.com/fuxiaohei) and [slene](https://github.com/slene) joined the team soon after. See [contributors page](https://github.com/gogits/gogs/graphs/contributors) for full list of contributors.
|
10
conf/app.ini
10
conf/app.ini
@ -1,10 +1,12 @@
|
|||||||
|
# App name that shows on every page title
|
||||||
APP_NAME = Gogs: Go Git Service
|
APP_NAME = Gogs: Go Git Service
|
||||||
|
# !!MUST CHANGE TO YOUR USER NAME!!
|
||||||
RUN_USER = lunny
|
RUN_USER = lunny
|
||||||
|
|
||||||
[repository]
|
[repository]
|
||||||
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories
|
ROOT = /Users/%(RUN_USER)s/git/gogs-repositories
|
||||||
LANG_IGNS=Google Go|C|Python|Ruby
|
LANG_IGNS=Google Go|C|Python|Ruby|C Sharp
|
||||||
LICENSES=Apache v2 License|GPL v2|MIT License|BSD (3-Clause) License
|
LICENSES=Apache v2 License|GPL v2|MIT License|Affero GPL|BSD (3-Clause) License
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
DOMAIN = gogits.org
|
DOMAIN = gogits.org
|
||||||
@ -12,11 +14,15 @@ HTTP_ADDR =
|
|||||||
HTTP_PORT = 3000
|
HTTP_PORT = 3000
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
|
# Either "mysql" or "postgres", it's your choice
|
||||||
DB_TYPE = mysql
|
DB_TYPE = mysql
|
||||||
HOST =
|
HOST =
|
||||||
NAME = gogs
|
NAME = gogs
|
||||||
USER = root
|
USER = root
|
||||||
PASSWD =
|
PASSWD =
|
||||||
|
# For "postgres" only, either "disable" or "verify-full"
|
||||||
|
SSL_MODE = disable
|
||||||
|
|
||||||
[security]
|
[security]
|
||||||
|
# !!CHANGE THIS TO KEEP YOUR USER DATA SAFE!!
|
||||||
USER_PASSWD_SALT = !#@FDEWREWR&*(
|
USER_PASSWD_SALT = !#@FDEWREWR&*(
|
||||||
|
108
conf/gitignore/C Sharp
Normal file
108
conf/gitignore/C Sharp
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
# Build Folders (you can keep bin if you'd like, to store dlls and pdbs)
|
||||||
|
[Bb]in/
|
||||||
|
[Oo]bj/
|
||||||
|
|
||||||
|
# mstest test results
|
||||||
|
TestResults
|
||||||
|
|
||||||
|
## Ignore Visual Studio temporary files, build results, and
|
||||||
|
## files generated by popular Visual Studio add-ons.
|
||||||
|
|
||||||
|
# User-specific files
|
||||||
|
*.suo
|
||||||
|
*.user
|
||||||
|
*.sln.docstates
|
||||||
|
|
||||||
|
# Build results
|
||||||
|
[Dd]ebug/
|
||||||
|
[Rr]elease/
|
||||||
|
x64/
|
||||||
|
*_i.c
|
||||||
|
*_p.c
|
||||||
|
*.ilk
|
||||||
|
*.meta
|
||||||
|
*.obj
|
||||||
|
*.pch
|
||||||
|
*.pdb
|
||||||
|
*.pgc
|
||||||
|
*.pgd
|
||||||
|
*.rsp
|
||||||
|
*.sbr
|
||||||
|
*.tlb
|
||||||
|
*.tli
|
||||||
|
*.tlh
|
||||||
|
*.tmp
|
||||||
|
*.log
|
||||||
|
*.vspscc
|
||||||
|
*.vssscc
|
||||||
|
.builds
|
||||||
|
|
||||||
|
# Visual C++ cache files
|
||||||
|
ipch/
|
||||||
|
*.aps
|
||||||
|
*.ncb
|
||||||
|
*.opensdf
|
||||||
|
*.sdf
|
||||||
|
|
||||||
|
# Visual Studio profiler
|
||||||
|
*.psess
|
||||||
|
*.vsp
|
||||||
|
*.vspx
|
||||||
|
|
||||||
|
# Guidance Automation Toolkit
|
||||||
|
*.gpState
|
||||||
|
|
||||||
|
# ReSharper is a .NET coding add-in
|
||||||
|
_ReSharper*
|
||||||
|
|
||||||
|
# NCrunch
|
||||||
|
*.ncrunch*
|
||||||
|
.*crunch*.local.xml
|
||||||
|
|
||||||
|
# Installshield output folder
|
||||||
|
[Ee]xpress
|
||||||
|
|
||||||
|
# DocProject is a documentation generator add-in
|
||||||
|
DocProject/buildhelp/
|
||||||
|
DocProject/Help/*.HxT
|
||||||
|
DocProject/Help/*.HxC
|
||||||
|
DocProject/Help/*.hhc
|
||||||
|
DocProject/Help/*.hhk
|
||||||
|
DocProject/Help/*.hhp
|
||||||
|
DocProject/Help/Html2
|
||||||
|
DocProject/Help/html
|
||||||
|
|
||||||
|
# Click-Once directory
|
||||||
|
publish
|
||||||
|
|
||||||
|
# Publish Web Output
|
||||||
|
*.Publish.xml
|
||||||
|
|
||||||
|
# NuGet Packages Directory
|
||||||
|
packages
|
||||||
|
|
||||||
|
# Windows Azure Build Output
|
||||||
|
csx
|
||||||
|
*.build.csdef
|
||||||
|
|
||||||
|
# Windows Store app package directory
|
||||||
|
AppPackages/
|
||||||
|
|
||||||
|
# Others
|
||||||
|
[Bb]in
|
||||||
|
[Oo]bj
|
||||||
|
sql
|
||||||
|
TestResults
|
||||||
|
[Tt]est[Rr]esult*
|
||||||
|
*.Cache
|
||||||
|
ClientBin
|
||||||
|
[Ss]tyle[Cc]op.*
|
||||||
|
~$*
|
||||||
|
*.dbmdl
|
||||||
|
Generated_Code #added for RIA/Silverlight projects
|
||||||
|
|
||||||
|
# Backup & report files from converting an old project file to a newer
|
||||||
|
# Visual Studio version. Backup files are not needed, because we have git ;-)
|
||||||
|
_UpgradeReport_Files/
|
||||||
|
Backup*/
|
||||||
|
UpgradeLog*.XML
|
661
conf/license/Affero GPL
Normal file
661
conf/license/Affero GPL
Normal file
File diff suppressed because it is too large
Load Diff
2
gogs.go
2
gogs.go
@ -20,7 +20,7 @@ import (
|
|||||||
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
// Test that go1.1 tag above is included in builds. main.go refers to this definition.
|
||||||
const go11tag = true
|
const go11tag = true
|
||||||
|
|
||||||
const APP_VER = "0.0.9.0317.1"
|
const APP_VER = "0.1.0.0317.1"
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
base.AppVer = APP_VER
|
base.AppVer = APP_VER
|
||||||
|
@ -9,11 +9,13 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Access types.
|
||||||
const (
|
const (
|
||||||
AU_READABLE = iota + 1
|
AU_READABLE = iota + 1
|
||||||
AU_WRITABLE
|
AU_WRITABLE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Access represents the accessibility of user and repository.
|
||||||
type Access struct {
|
type Access struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserName string `xorm:"unique(s)"`
|
UserName string `xorm:"unique(s)"`
|
||||||
@ -22,12 +24,13 @@ type Access struct {
|
|||||||
Created time.Time `xorm:"created"`
|
Created time.Time `xorm:"created"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddAccess adds new access record.
|
||||||
func AddAccess(access *Access) error {
|
func AddAccess(access *Access) error {
|
||||||
_, err := orm.Insert(access)
|
_, err := orm.Insert(access)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// if one user can read or write one repository
|
// HasAccess returns true if someone can read or write given repository.
|
||||||
func HasAccess(userName, repoName string, mode int) (bool, error) {
|
func HasAccess(userName, repoName string, mode int) (bool, error) {
|
||||||
return orm.Get(&Access{
|
return orm.Get(&Access{
|
||||||
Id: 0,
|
Id: 0,
|
||||||
|
@ -19,7 +19,7 @@ const (
|
|||||||
OP_PULL_REQUEST
|
OP_PULL_REQUEST
|
||||||
)
|
)
|
||||||
|
|
||||||
// An Action represents
|
// Action represents user operation type and information to the repository.
|
||||||
type Action struct {
|
type Action struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 // Receiver user id.
|
UserId int64 // Receiver user id.
|
||||||
|
@ -7,10 +7,9 @@ package models
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
_ "github.com/go-sql-driver/mysql"
|
_ "github.com/go-sql-driver/mysql"
|
||||||
|
_ "github.com/lib/pq"
|
||||||
"github.com/lunny/xorm"
|
"github.com/lunny/xorm"
|
||||||
|
|
||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
@ -47,54 +46,50 @@ func setEngine() {
|
|||||||
dbName := base.Cfg.MustValue("database", "NAME")
|
dbName := base.Cfg.MustValue("database", "NAME")
|
||||||
dbUser := base.Cfg.MustValue("database", "USER")
|
dbUser := base.Cfg.MustValue("database", "USER")
|
||||||
dbPwd := base.Cfg.MustValue("database", "PASSWD")
|
dbPwd := base.Cfg.MustValue("database", "PASSWD")
|
||||||
|
sslMode := base.Cfg.MustValue("database", "SSL_MODE")
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
switch dbType {
|
switch dbType {
|
||||||
case "mysql":
|
case "mysql":
|
||||||
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%v@%v/%v?charset=utf8",
|
orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%s@%s/%s?charset=utf8",
|
||||||
dbUser, dbPwd, dbHost, dbName))
|
dbUser, dbPwd, dbHost, dbName))
|
||||||
|
case "postgres":
|
||||||
|
orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
|
||||||
|
dbUser, dbPwd, dbName, sslMode))
|
||||||
default:
|
default:
|
||||||
fmt.Printf("Unknown database type: %s\n", dbType)
|
fmt.Printf("Unknown database type: %s\n", dbType)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("models.init -> fail to conntect database: %s\n", dbType)
|
fmt.Printf("models.init(fail to conntect database): %v\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO: for serv command, MUST remove the output to os.stdout, so
|
// TODO: for serv command, MUST remove the output to os.stdout, so
|
||||||
// use log file to instead print to stdout
|
// use log file to instead print to stdout
|
||||||
|
|
||||||
//x.ShowDebug = true
|
//x.ShowDebug = true
|
||||||
//orm.ShowErr = true
|
//orm.ShowErr = true
|
||||||
f, _ := os.Create("xorm.log")
|
f, err := os.Create("xorm.log")
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("models.init(fail to create xorm.log): %v\n", err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
orm.Logger = f
|
orm.Logger = f
|
||||||
orm.ShowSQL = true
|
orm.ShowSQL = true
|
||||||
|
|
||||||
|
// Determine and create root git reposiroty path.
|
||||||
RepoRootPath = base.Cfg.MustValue("repository", "ROOT")
|
RepoRootPath = base.Cfg.MustValue("repository", "ROOT")
|
||||||
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
|
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
|
||||||
fmt.Printf("models.init -> fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
|
fmt.Printf("models.init(fail to create RepoRootPath(%s)): %v\n", RepoRootPath, err)
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
|
|
||||||
homeDir, err := com.HomeDir()
|
|
||||||
if err != nil {
|
|
||||||
fmt.Printf("models.init -> fail to get homeDir: %v\n", err)
|
|
||||||
os.Exit(2)
|
|
||||||
}
|
|
||||||
sshPath := filepath.Join(homeDir, ".ssh")
|
|
||||||
if err = os.MkdirAll(sshPath, os.ModePerm); err != nil {
|
|
||||||
fmt.Printf("models.init -> fail to create sshPath(%s): %v\n", sshPath, err)
|
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
setEngine()
|
setEngine()
|
||||||
err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Access), new(Action))
|
if err := orm.Sync(new(User), new(PublicKey), new(Repository), new(Access), new(Action)); err != nil {
|
||||||
if err != nil {
|
fmt.Printf("sync database struct error: %v\n", err)
|
||||||
fmt.Printf("sync database struct error: %s\n", err)
|
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,6 +9,7 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
@ -20,16 +21,19 @@ import (
|
|||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
const (
|
||||||
sshOpLocker = sync.Mutex{}
|
|
||||||
//publicKeyRootPath string
|
|
||||||
sshPath string
|
|
||||||
appPath string
|
|
||||||
// "### autogenerated by gitgos, DO NOT EDIT\n"
|
// "### autogenerated by gitgos, DO NOT EDIT\n"
|
||||||
tmplPublicKey = "command=\"%s serv key-%d\",no-port-forwarding," +
|
TPL_PUBLICK_KEY = `command="%s serv key-%d",no-port-forwarding, no-X11-forwarding,no-agent-forwarding,no-pty %s`
|
||||||
"no-X11-forwarding,no-agent-forwarding,no-pty %s\n"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
sshOpLocker = sync.Mutex{}
|
||||||
|
|
||||||
|
sshPath string
|
||||||
|
appPath string
|
||||||
|
)
|
||||||
|
|
||||||
|
// exePath returns the executable path.
|
||||||
func exePath() (string, error) {
|
func exePath() (string, error) {
|
||||||
file, err := exec.LookPath(os.Args[0])
|
file, err := exec.LookPath(os.Args[0])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -38,6 +42,7 @@ func exePath() (string, error) {
|
|||||||
return filepath.Abs(file)
|
return filepath.Abs(file)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// homeDir returns the home directory of current user.
|
||||||
func homeDir() string {
|
func homeDir() string {
|
||||||
home, err := com.HomeDir()
|
home, err := com.HomeDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -48,15 +53,22 @@ func homeDir() string {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
appPath, err = exePath()
|
appPath, err = exePath()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
println(err.Error())
|
fmt.Printf("publickey.init(fail to get app path): %v\n", err)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Determine and create .ssh path.
|
||||||
sshPath = filepath.Join(homeDir(), ".ssh")
|
sshPath = filepath.Join(homeDir(), ".ssh")
|
||||||
|
if err = os.MkdirAll(sshPath, os.ModePerm); err != nil {
|
||||||
|
fmt.Printf("publickey.init(fail to create sshPath(%s)): %v\n", sshPath, err)
|
||||||
|
os.Exit(2)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PublicKey represents a SSH key of user.
|
||||||
type PublicKey struct {
|
type PublicKey struct {
|
||||||
Id int64
|
Id int64
|
||||||
OwnerId int64 `xorm:"index"`
|
OwnerId int64 `xorm:"index"`
|
||||||
@ -71,10 +83,12 @@ var (
|
|||||||
ErrKeyAlreadyExist = errors.New("Public key already exist")
|
ErrKeyAlreadyExist = errors.New("Public key already exist")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// GenAuthorizedKey returns formatted public key string.
|
||||||
func GenAuthorizedKey(keyId int64, key string) string {
|
func GenAuthorizedKey(keyId int64, key string) string {
|
||||||
return fmt.Sprintf(tmplPublicKey, appPath, keyId, key)
|
return fmt.Sprintf(TPL_PUBLICK_KEY+"\n", appPath, keyId, key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddPublicKey adds new public key to database and SSH key file.
|
||||||
func AddPublicKey(key *PublicKey) (err error) {
|
func AddPublicKey(key *PublicKey) (err error) {
|
||||||
// Check if public key name has been used.
|
// Check if public key name has been used.
|
||||||
has, err := orm.Get(key)
|
has, err := orm.Get(key)
|
||||||
@ -88,14 +102,9 @@ func AddPublicKey(key *PublicKey) (err error) {
|
|||||||
tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
|
tmpPath := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()),
|
||||||
"id_rsa.pub")
|
"id_rsa.pub")
|
||||||
os.MkdirAll(path.Dir(tmpPath), os.ModePerm)
|
os.MkdirAll(path.Dir(tmpPath), os.ModePerm)
|
||||||
f, err := os.Create(tmpPath)
|
if err = ioutil.WriteFile(tmpPath, []byte(key.Content), os.ModePerm); err != nil {
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if _, err = f.WriteString(key.Content); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
f.Close()
|
|
||||||
stdout, _, err := com.ExecCmd("ssh-keygen", "-l", "-f", tmpPath)
|
stdout, _, err := com.ExecCmd("ssh-keygen", "-l", "-f", tmpPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -108,7 +117,6 @@ func AddPublicKey(key *PublicKey) (err error) {
|
|||||||
if _, err = orm.Insert(key); err != nil {
|
if _, err = orm.Insert(key); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = SaveAuthorizedKeyFile(key); err != nil {
|
if err = SaveAuthorizedKeyFile(key); err != nil {
|
||||||
if _, err2 := orm.Delete(key); err2 != nil {
|
if _, err2 := orm.Delete(key); err2 != nil {
|
||||||
return err2
|
return err2
|
||||||
@ -121,6 +129,7 @@ func AddPublicKey(key *PublicKey) (err error) {
|
|||||||
|
|
||||||
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
|
// DeletePublicKey deletes SSH key information both in database and authorized_keys file.
|
||||||
func DeletePublicKey(key *PublicKey) (err error) {
|
func DeletePublicKey(key *PublicKey) (err error) {
|
||||||
|
// Delete SSH key in database.
|
||||||
has, err := orm.Id(key.Id).Get(key)
|
has, err := orm.Id(key.Id).Get(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -131,6 +140,7 @@ func DeletePublicKey(key *PublicKey) (err error) {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Delete SSH key in SSH key file.
|
||||||
sshOpLocker.Lock()
|
sshOpLocker.Lock()
|
||||||
defer sshOpLocker.Unlock()
|
defer sshOpLocker.Unlock()
|
||||||
|
|
||||||
@ -182,16 +192,17 @@ func DeletePublicKey(key *PublicKey) (err error) {
|
|||||||
if err = os.Remove(p); err != nil {
|
if err = os.Remove(p); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return os.Rename(tmpP, p)
|
return os.Rename(tmpP, p)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListPublicKey returns a list of public keys that user has.
|
||||||
func ListPublicKey(userId int64) ([]PublicKey, error) {
|
func ListPublicKey(userId int64) ([]PublicKey, error) {
|
||||||
keys := make([]PublicKey, 0)
|
keys := make([]PublicKey, 0)
|
||||||
err := orm.Find(&keys, &PublicKey{OwnerId: userId})
|
err := orm.Find(&keys, &PublicKey{OwnerId: userId})
|
||||||
return keys, err
|
return keys, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SaveAuthorizedKeyFile writes SSH key content to SSH key file.
|
||||||
func SaveAuthorizedKeyFile(key *PublicKey) error {
|
func SaveAuthorizedKeyFile(key *PublicKey) error {
|
||||||
sshOpLocker.Lock()
|
sshOpLocker.Lock()
|
||||||
defer sshOpLocker.Unlock()
|
defer sshOpLocker.Unlock()
|
||||||
@ -203,7 +214,6 @@ func SaveAuthorizedKeyFile(key *PublicKey) error {
|
|||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
|
|
||||||
//os.Chmod(p, 0600)
|
|
||||||
_, err = f.WriteString(GenAuthorizedKey(key.Id, key.Content))
|
_, err = f.WriteString(GenAuthorizedKey(key.Id, key.Content))
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
241
models/repo.go
241
models/repo.go
File diff suppressed because it is too large
Load Diff
205
models/repo2.go
205
models/repo2.go
@ -1,205 +0,0 @@
|
|||||||
// Copyright 2014 The Gogs Authors. All rights reserved.
|
|
||||||
// Use of this source code is governed by a MIT-style
|
|
||||||
// license that can be found in the LICENSE file.
|
|
||||||
|
|
||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"path"
|
|
||||||
"strings"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
|
||||||
|
|
||||||
"github.com/gogits/git"
|
|
||||||
)
|
|
||||||
|
|
||||||
type Commit struct {
|
|
||||||
Author string
|
|
||||||
Email string
|
|
||||||
Date time.Time
|
|
||||||
SHA string
|
|
||||||
Message string
|
|
||||||
}
|
|
||||||
|
|
||||||
var (
|
|
||||||
ErrRepoFileNotLoaded = fmt.Errorf("repo file not loaded")
|
|
||||||
)
|
|
||||||
|
|
||||||
type RepoFile struct {
|
|
||||||
*git.TreeEntry
|
|
||||||
Path string
|
|
||||||
Message string
|
|
||||||
Created time.Time
|
|
||||||
Size int64
|
|
||||||
Repo *git.Repository
|
|
||||||
LastCommit string
|
|
||||||
}
|
|
||||||
|
|
||||||
func (file *RepoFile) LookupBlob() (*git.Blob, error) {
|
|
||||||
if file.Repo == nil {
|
|
||||||
return nil, ErrRepoFileNotLoaded
|
|
||||||
}
|
|
||||||
|
|
||||||
return file.Repo.LookupBlob(file.Id)
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetBranches(userName, reposName string) ([]string, error) {
|
|
||||||
repo, err := git.OpenRepository(RepoPath(userName, reposName))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
refs, err := repo.AllReferences()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
brs := make([]string, len(refs))
|
|
||||||
for i, ref := range refs {
|
|
||||||
brs[i] = ref.Name
|
|
||||||
}
|
|
||||||
return brs, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
|
|
||||||
repo, err := git.OpenRepository(RepoPath(userName, reposName))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
ref, err := repo.LookupReference("refs/heads/" + branchName)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
lastCommit, err := repo.LookupCommit(ref.Oid)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
var repodirs []*RepoFile
|
|
||||||
var repofiles []*RepoFile
|
|
||||||
lastCommit.Tree.Walk(func(dirname string, entry *git.TreeEntry) int {
|
|
||||||
if dirname == rpath {
|
|
||||||
size, err := repo.ObjectSize(entry.Id)
|
|
||||||
if err != nil {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var cm = lastCommit
|
|
||||||
|
|
||||||
for {
|
|
||||||
if cm.ParentCount() == 0 {
|
|
||||||
break
|
|
||||||
} else if cm.ParentCount() == 1 {
|
|
||||||
pt, _ := repo.SubTree(cm.Parent(0).Tree, dirname)
|
|
||||||
if pt == nil {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
pEntry := pt.EntryByName(entry.Name)
|
|
||||||
if pEntry == nil || !pEntry.Id.Equal(entry.Id) {
|
|
||||||
break
|
|
||||||
} else {
|
|
||||||
cm = cm.Parent(0)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
var emptyCnt = 0
|
|
||||||
var sameIdcnt = 0
|
|
||||||
for i := 0; i < cm.ParentCount(); i++ {
|
|
||||||
p := cm.Parent(i)
|
|
||||||
pt, _ := repo.SubTree(p.Tree, dirname)
|
|
||||||
var pEntry *git.TreeEntry
|
|
||||||
if pt != nil {
|
|
||||||
pEntry = pt.EntryByName(entry.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
if pEntry == nil {
|
|
||||||
if emptyCnt == cm.ParentCount()-1 {
|
|
||||||
goto loop
|
|
||||||
} else {
|
|
||||||
emptyCnt = emptyCnt + 1
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if !pEntry.Id.Equal(entry.Id) {
|
|
||||||
goto loop
|
|
||||||
} else {
|
|
||||||
if sameIdcnt == cm.ParentCount()-1 {
|
|
||||||
// TODO: now follow the first parent commit?
|
|
||||||
cm = cm.Parent(0)
|
|
||||||
break
|
|
||||||
}
|
|
||||||
sameIdcnt = sameIdcnt + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
loop:
|
|
||||||
|
|
||||||
rp := &RepoFile{
|
|
||||||
entry,
|
|
||||||
path.Join(dirname, entry.Name),
|
|
||||||
cm.Message(),
|
|
||||||
cm.Committer.When,
|
|
||||||
size,
|
|
||||||
repo,
|
|
||||||
cm.Id().String(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if entry.IsFile() {
|
|
||||||
repofiles = append(repofiles, rp)
|
|
||||||
} else if entry.IsDir() {
|
|
||||||
repodirs = append(repodirs, rp)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
})
|
|
||||||
|
|
||||||
return append(repodirs, repofiles...), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetLastestCommit(userName, repoName string) (*Commit, error) {
|
|
||||||
stdout, _, err := com.ExecCmd("git", "--git-dir="+RepoPath(userName, repoName), "log", "-1")
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
commit := new(Commit)
|
|
||||||
for _, line := range strings.Split(stdout, "\n") {
|
|
||||||
if len(line) == 0 {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
switch {
|
|
||||||
case line[0] == 'c':
|
|
||||||
commit.SHA = line[7:]
|
|
||||||
case line[0] == 'A':
|
|
||||||
infos := strings.SplitN(line, " ", 3)
|
|
||||||
commit.Author = infos[1]
|
|
||||||
commit.Email = infos[2][1 : len(infos[2])-1]
|
|
||||||
case line[0] == 'D':
|
|
||||||
commit.Date, err = time.Parse("Mon Jan 02 15:04:05 2006 -0700", line[8:])
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
case line[:4] == " ":
|
|
||||||
commit.Message = line[4:]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return commit, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func GetCommits(userName, reposName, branchname string) ([]*git.Commit, error) {
|
|
||||||
repo, err := git.OpenRepository(RepoPath(userName, reposName))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname))
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
return r.AllCommits()
|
|
||||||
}
|
|
@ -19,7 +19,9 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/base"
|
"github.com/gogits/gogs/modules/base"
|
||||||
)
|
)
|
||||||
|
|
||||||
var UserPasswdSalt string
|
var (
|
||||||
|
UserPasswdSalt string
|
||||||
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
UserPasswdSalt = base.Cfg.MustValue("security", "USER_PASSWD_SALT")
|
UserPasswdSalt = base.Cfg.MustValue("security", "USER_PASSWD_SALT")
|
||||||
@ -37,7 +39,7 @@ const (
|
|||||||
LT_LDAP
|
LT_LDAP
|
||||||
)
|
)
|
||||||
|
|
||||||
// A User represents the object of individual and member of organization.
|
// User represents the object of individual and member of organization.
|
||||||
type User struct {
|
type User struct {
|
||||||
Id int64
|
Id int64
|
||||||
LowerName string `xorm:"unique not null"`
|
LowerName string `xorm:"unique not null"`
|
||||||
@ -58,15 +60,16 @@ type User struct {
|
|||||||
Updated time.Time `xorm:"updated"`
|
Updated time.Time `xorm:"updated"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HomeLink returns the user home page link.
|
||||||
func (user *User) HomeLink() string {
|
func (user *User) HomeLink() string {
|
||||||
return "/user/" + user.LowerName
|
return "/user/" + user.LowerName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AvatarLink returns the user gravatar link.
|
||||||
func (user *User) AvatarLink() string {
|
func (user *User) AvatarLink() string {
|
||||||
return "http://1.gravatar.com/avatar/" + user.Avatar
|
return "http://1.gravatar.com/avatar/" + user.Avatar
|
||||||
}
|
}
|
||||||
|
|
||||||
// A Follow represents
|
|
||||||
type Follow struct {
|
type Follow struct {
|
||||||
Id int64
|
Id int64
|
||||||
UserId int64 `xorm:"unique(s)"`
|
UserId int64 `xorm:"unique(s)"`
|
||||||
@ -87,6 +90,7 @@ func IsUserExist(name string) (bool, error) {
|
|||||||
return orm.Get(&User{LowerName: strings.ToLower(name)})
|
return orm.Get(&User{LowerName: strings.ToLower(name)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsEmailUsed returns true if the e-mail has been used.
|
||||||
func IsEmailUsed(email string) (bool, error) {
|
func IsEmailUsed(email string) (bool, error) {
|
||||||
return orm.Get(&User{Email: email})
|
return orm.Get(&User{Email: email})
|
||||||
}
|
}
|
||||||
@ -121,16 +125,12 @@ func RegisterUser(user *User) (err error) {
|
|||||||
user.AvatarEmail = user.Email
|
user.AvatarEmail = user.Email
|
||||||
if err = user.EncodePasswd(); err != nil {
|
if err = user.EncodePasswd(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
} else if _, err = orm.Insert(user); err != nil {
|
||||||
if _, err = orm.Insert(user); err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
} else if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil {
|
||||||
|
|
||||||
if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil {
|
|
||||||
|
|
||||||
if _, err := orm.Id(user.Id).Delete(&User{}); err != nil {
|
if _, err := orm.Id(user.Id).Delete(&User{}); err != nil {
|
||||||
return errors.New(fmt.Sprintf(
|
return errors.New(fmt.Sprintf(
|
||||||
"both create userpath %s and delete table record faild", user.Name))
|
"both create userpath %s and delete table record faild: %v", user.Name, err))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -188,23 +188,28 @@ func (user *User) EncodePasswd() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UserPath returns the path absolute path of user repositories.
|
||||||
func UserPath(userName string) string {
|
func UserPath(userName string) string {
|
||||||
return filepath.Join(RepoRootPath, userName)
|
return filepath.Join(RepoRootPath, userName)
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetUserByKeyId(keyId int64) (*User, error) {
|
func GetUserByKeyId(keyId int64) (*User, error) {
|
||||||
user := new(User)
|
user := new(User)
|
||||||
has, err := orm.Sql("select a.* from user as a, public_key as b where a.id = b.owner_id and b.id=?", keyId).Get(user)
|
rawSql := "SELECT a.* FROM user AS a, public_key AS b WHERE a.id = b.owner_id AND b.id=?"
|
||||||
|
if base.Cfg.MustValue("database", "DB_TYPE") == "postgres" {
|
||||||
|
rawSql = "SELECT a.* FROM \"user\" AS a, public_key AS b WHERE a.id = b.owner_id AND b.id=?"
|
||||||
|
}
|
||||||
|
has, err := orm.Sql(rawSql, keyId).Get(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
} else if !has {
|
||||||
if !has {
|
|
||||||
err = errors.New("not exist key owner")
|
err = errors.New("not exist key owner")
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserById returns the user object by given id if exists.
|
||||||
func GetUserById(id int64) (*User, error) {
|
func GetUserById(id int64) (*User, error) {
|
||||||
user := new(User)
|
user := new(User)
|
||||||
has, err := orm.Id(id).Get(user)
|
has, err := orm.Id(id).Get(user)
|
||||||
@ -217,6 +222,7 @@ func GetUserById(id int64) (*User, error) {
|
|||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUserByName returns the user object by given name if exists.
|
||||||
func GetUserByName(name string) (*User, error) {
|
func GetUserByName(name string) (*User, error) {
|
||||||
if len(name) == 0 {
|
if len(name) == 0 {
|
||||||
return nil, ErrUserNotExist
|
return nil, ErrUserNotExist
|
||||||
@ -227,8 +233,7 @@ func GetUserByName(name string) (*User, error) {
|
|||||||
has, err := orm.Get(user)
|
has, err := orm.Get(user)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
} else if !has {
|
||||||
if !has {
|
|
||||||
return nil, ErrUserNotExist
|
return nil, ErrUserNotExist
|
||||||
}
|
}
|
||||||
return user, nil
|
return user, nil
|
||||||
@ -242,32 +247,39 @@ func LoginUserPlain(name, passwd string) (*User, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
has, err := orm.Get(&user)
|
has, err := orm.Get(&user)
|
||||||
if !has {
|
|
||||||
err = ErrUserNotExist
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
} else if !has {
|
||||||
|
err = ErrUserNotExist
|
||||||
}
|
}
|
||||||
return &user, nil
|
return &user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// FollowUser marks someone be another's follower.
|
// FollowUser marks someone be another's follower.
|
||||||
func FollowUser(userId int64, followId int64) error {
|
func FollowUser(userId int64, followId int64) (err error) {
|
||||||
session := orm.NewSession()
|
session := orm.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
session.Begin()
|
session.Begin()
|
||||||
_, err := session.Insert(&Follow{UserId: userId, FollowId: followId})
|
|
||||||
if err != nil {
|
if _, err = session.Insert(&Follow{UserId: userId, FollowId: followId}); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = session.Exec("update user set num_followers = num_followers + 1 where id = ?", followId)
|
|
||||||
if err != nil {
|
rawSql := "UPDATE user SET num_followers = num_followers + 1 WHERE id = ?"
|
||||||
|
if base.Cfg.MustValue("database", "DB_TYPE") == "postgres" {
|
||||||
|
rawSql = "UPDATE \"user\" SET num_followers = num_followers + 1 WHERE id = ?"
|
||||||
|
}
|
||||||
|
if _, err = session.Exec(rawSql, followId); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = session.Exec("update user set num_followings = num_followings + 1 where id = ?", userId)
|
|
||||||
if err != nil {
|
rawSql = "UPDATE user SET num_followings = num_followings + 1 WHERE id = ?"
|
||||||
|
if base.Cfg.MustValue("database", "DB_TYPE") == "postgres" {
|
||||||
|
rawSql = "UPDATE \"user\" SET num_followings = num_followings + 1 WHERE id = ?"
|
||||||
|
}
|
||||||
|
if _, err = session.Exec(rawSql, userId); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@ -275,22 +287,30 @@ func FollowUser(userId int64, followId int64) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// UnFollowUser unmarks someone be another's follower.
|
// UnFollowUser unmarks someone be another's follower.
|
||||||
func UnFollowUser(userId int64, unFollowId int64) error {
|
func UnFollowUser(userId int64, unFollowId int64) (err error) {
|
||||||
session := orm.NewSession()
|
session := orm.NewSession()
|
||||||
defer session.Close()
|
defer session.Close()
|
||||||
session.Begin()
|
session.Begin()
|
||||||
_, err := session.Delete(&Follow{UserId: userId, FollowId: unFollowId})
|
|
||||||
if err != nil {
|
if _, err = session.Delete(&Follow{UserId: userId, FollowId: unFollowId}); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = session.Exec("update user set num_followers = num_followers - 1 where id = ?", unFollowId)
|
|
||||||
if err != nil {
|
rawSql := "UPDATE user SET num_followers = num_followers - 1 WHERE id = ?"
|
||||||
|
if base.Cfg.MustValue("database", "DB_TYPE") == "postgres" {
|
||||||
|
rawSql = "UPDATE \"user\" SET num_followers = num_followers - 1 WHERE id = ?"
|
||||||
|
}
|
||||||
|
if _, err = session.Exec(rawSql, unFollowId); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = session.Exec("update user set num_followings = num_followings - 1 where id = ?", userId)
|
|
||||||
if err != nil {
|
rawSql = "UPDATE user SET num_followings = num_followings - 1 WHERE id = ?"
|
||||||
|
if base.Cfg.MustValue("database", "DB_TYPE") == "postgres" {
|
||||||
|
rawSql = "UPDATE \"user\" SET num_followings = num_followings - 1 WHERE id = ?"
|
||||||
|
}
|
||||||
|
if _, err = session.Exec(rawSql, userId); err != nil {
|
||||||
session.Rollback()
|
session.Rollback()
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ import (
|
|||||||
"github.com/gogits/gogs/modules/log"
|
"github.com/gogits/gogs/modules/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SignedInId returns the id of signed in user.
|
||||||
func SignedInId(session sessions.Session) int64 {
|
func SignedInId(session sessions.Session) int64 {
|
||||||
userId := session.Get("userId")
|
userId := session.Get("userId")
|
||||||
if userId == nil {
|
if userId == nil {
|
||||||
@ -32,6 +33,7 @@ func SignedInId(session sessions.Session) int64 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignedInName returns the name of signed in user.
|
||||||
func SignedInName(session sessions.Session) string {
|
func SignedInName(session sessions.Session) string {
|
||||||
userName := session.Get("userName")
|
userName := session.Get("userName")
|
||||||
if userName == nil {
|
if userName == nil {
|
||||||
@ -43,6 +45,7 @@ func SignedInName(session sessions.Session) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignedInUser returns the user object of signed user.
|
||||||
func SignedInUser(session sessions.Session) *models.User {
|
func SignedInUser(session sessions.Session) *models.User {
|
||||||
id := SignedInId(session)
|
id := SignedInId(session)
|
||||||
if id <= 0 {
|
if id <= 0 {
|
||||||
@ -57,6 +60,7 @@ func SignedInUser(session sessions.Session) *models.User {
|
|||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IsSignedIn check if any user has signed in.
|
||||||
func IsSignedIn(session sessions.Session) bool {
|
func IsSignedIn(session sessions.Session) bool {
|
||||||
return SignedInId(session) > 0
|
return SignedInId(session) > 0
|
||||||
}
|
}
|
||||||
|
@ -4,8 +4,6 @@
|
|||||||
|
|
||||||
package base
|
package base
|
||||||
|
|
||||||
import ()
|
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Type TmplData represents data in the templates.
|
// Type TmplData represents data in the templates.
|
||||||
TmplData map[string]interface{}
|
TmplData map[string]interface{}
|
||||||
|
@ -48,6 +48,7 @@ func init() {
|
|||||||
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
fmt.Printf("Cannot load config file '%s'\n", cfgPath)
|
||||||
os.Exit(2)
|
os.Exit(2)
|
||||||
}
|
}
|
||||||
|
Cfg.BlockMode = false
|
||||||
|
|
||||||
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
|
||||||
if com.IsFile(cfgPath) {
|
if com.IsFile(cfgPath) {
|
||||||
|
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/codegangsta/martini"
|
"github.com/codegangsta/martini"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// SignInRequire requires user to sign in.
|
||||||
func SignInRequire(redirect bool) martini.Handler {
|
func SignInRequire(redirect bool) martini.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if !ctx.IsSigned {
|
if !ctx.IsSigned {
|
||||||
@ -19,6 +20,7 @@ func SignInRequire(redirect bool) martini.Handler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SignOutRequire requires user to sign out.
|
||||||
func SignOutRequire() martini.Handler {
|
func SignOutRequire() martini.Handler {
|
||||||
return func(ctx *Context) {
|
return func(ctx *Context) {
|
||||||
if ctx.IsSigned {
|
if ctx.IsSigned {
|
||||||
|
4
serve.go
4
serve.go
@ -1,3 +1,7 @@
|
|||||||
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
<div class="collapse navbar-collapse">
|
<div class="collapse navbar-collapse">
|
||||||
<ul class="nav navbar-nav">
|
<ul class="nav navbar-nav">
|
||||||
<li class="{{if .IsRepoToolbarSource}}active{{end}}"><a href="/{{.RepositoryLink}}">Source</a></li>
|
<li class="{{if .IsRepoToolbarSource}}active{{end}}"><a href="/{{.RepositoryLink}}">Source</a></li>
|
||||||
<li class="{{if .IsRepoToolbarCommits}}active{{end}}"><a href="/{{.RepositoryLink}}/commits">Commits</a></li>
|
<li class="{{if .IsRepoToolbarCommits}}active{{end}}"><a href="/{{.RepositoryLink}}/commits/{{.Branchname}}">Commits</a></li>
|
||||||
<li class="{{if .IsRepoToolbarBranches}}active{{end}}"><a href="/{{.RepositoryLink}}/branches">Branches</a></li>
|
<li class="{{if .IsRepoToolbarBranches}}active{{end}}"><a href="/{{.RepositoryLink}}/branches">Branches</a></li>
|
||||||
<li class="{{if .IsRepoToolbarPulls}}active{{end}}"><a href="/{{.RepositoryLink}}/pulls">Pull Requests</a></li>
|
<li class="{{if .IsRepoToolbarPulls}}active{{end}}"><a href="/{{.RepositoryLink}}/pulls">Pull Requests</a></li>
|
||||||
<li class="{{if .IsRepoToolbarIssues}}active{{end}}"><a href="/{{.RepositoryLink}}/issues">Issues <!--<span class="badge">42</span>--></a></li>
|
<li class="{{if .IsRepoToolbarIssues}}active{{end}}"><a href="/{{.RepositoryLink}}/issues">Issues <!--<span class="badge">42</span>--></a></li>
|
||||||
|
Reference in New Issue
Block a user