Merge branch 'dev' of github.com:gogits/gogs into dev
This commit is contained in:
commit
a85f242030
41 changed files with 231 additions and 228 deletions
|
@ -77,12 +77,12 @@ func init() {
|
|||
// PublicKey represents a SSH key of user.
|
||||
type PublicKey struct {
|
||||
Id int64
|
||||
OwnerId int64 `xorm:"unique(s) index not null"`
|
||||
Name string `xorm:"unique(s) not null"`
|
||||
OwnerId int64 `xorm:"UNIQUE(s) INDEX NOT NULL"`
|
||||
Name string `xorm:"UNIQUE(s) NOT NULL"`
|
||||
Fingerprint string
|
||||
Content string `xorm:"TEXT not null"`
|
||||
Created time.Time `xorm:"created"`
|
||||
Updated time.Time `xorm:"updated"`
|
||||
Content string `xorm:"TEXT NOT NULL"`
|
||||
Created time.Time `xorm:"CREATED"`
|
||||
Updated time.Time `xorm:"UPDATED"`
|
||||
}
|
||||
|
||||
// GenAuthorizedKey returns formatted public key string.
|
||||
|
@ -107,9 +107,9 @@ func AddPublicKey(key *PublicKey) (err error) {
|
|||
if err = ioutil.WriteFile(tmpPath, []byte(key.Content), os.ModePerm); err != nil {
|
||||
return err
|
||||
}
|
||||
stdout, _, err := com.ExecCmd("ssh-keygen", "-l", "-f", tmpPath)
|
||||
stdout, stderr, err := com.ExecCmd("ssh-keygen", "-l", "-f", tmpPath)
|
||||
if err != nil {
|
||||
return err
|
||||
return errors.New("ssh-keygen -l -f: " + stderr)
|
||||
} else if len(stdout) < 2 {
|
||||
return errors.New("Not enough output for calculating fingerprint")
|
||||
}
|
||||
|
|
|
@ -159,9 +159,7 @@ func MirrorUpdate() {
|
|||
repoPath := filepath.Join(base.RepoRootPath, m.RepoName+".git")
|
||||
_, stderr, err := com.ExecCmdDir(repoPath, "git", "remote", "update")
|
||||
if err != nil {
|
||||
return err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return errors.New(stderr)
|
||||
return errors.New("git remote update: " + stderr)
|
||||
} else if err = git.UnpackRefs(repoPath); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -177,9 +175,7 @@ func MirrorUpdate() {
|
|||
func MirrorRepository(repoId int64, userName, repoName, repoPath, url string) error {
|
||||
_, stderr, err := com.ExecCmd("git", "clone", "--mirror", url, repoPath)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return errors.New(stderr)
|
||||
return errors.New("git clone --mirror: " + stderr)
|
||||
}
|
||||
|
||||
if _, err = orm.InsertOne(&Mirror{
|
||||
|
@ -219,23 +215,17 @@ func MigrateRepository(user *User, name, desc string, private, mirror bool, url
|
|||
// Clone from local repository.
|
||||
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
|
||||
if err != nil {
|
||||
return repo, err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return repo, errors.New("git clone: " + stderr)
|
||||
}
|
||||
|
||||
// Pull data from source.
|
||||
_, stderr, err = com.ExecCmdDir(tmpDir, "git", "pull", url)
|
||||
if err != nil {
|
||||
return repo, err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return repo, errors.New("git pull: " + stderr)
|
||||
}
|
||||
|
||||
// Push data to local repository.
|
||||
if _, stderr, err = com.ExecCmdDir(tmpDir, "git", "push", "origin", "master"); err != nil {
|
||||
return repo, err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return repo, errors.New("git push: " + stderr)
|
||||
}
|
||||
|
||||
|
@ -403,10 +393,11 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
|
|||
return err
|
||||
}
|
||||
|
||||
rp := strings.NewReplacer("\\", "/", " ", "\\ ")
|
||||
// hook/post-update
|
||||
if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
|
||||
fmt.Sprintf("#!/usr/bin/env %s\n%s update $1 $2 $3\n", base.ScriptType,
|
||||
strings.Replace(appPath, "\\", "/", -1))); err != nil {
|
||||
rp.Replace(appPath))); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
@ -428,8 +419,6 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
|
|||
|
||||
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
|
||||
if err != nil {
|
||||
return err
|
||||
} else if strings.Contains(stderr, "fatal:") {
|
||||
return errors.New("git clone: " + stderr)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 models
|
||||
|
||||
import (
|
||||
|
@ -5,9 +9,11 @@ import (
|
|||
"os/exec"
|
||||
"strings"
|
||||
|
||||
"github.com/gogits/git"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
qlog "github.com/qiniu/log"
|
||||
|
||||
"github.com/gogits/git"
|
||||
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
)
|
||||
|
||||
func Update(refName, oldCommitId, newCommitId, userName, repoName string, userId int64) {
|
||||
|
|
|
@ -410,21 +410,27 @@ func GetUserByEmail(email string) (*User, error) {
|
|||
}
|
||||
|
||||
// LoginUserPlain validates user by raw user name and password.
|
||||
func LoginUserPlain(name, passwd string) (*User, error) {
|
||||
user := User{LowerName: strings.ToLower(name)}
|
||||
has, err := orm.Get(&user)
|
||||
func LoginUserPlain(uname, passwd string) (*User, error) {
|
||||
var u *User
|
||||
if strings.Contains(uname, "@") {
|
||||
u = &User{Email: uname}
|
||||
} else {
|
||||
u = &User{LowerName: strings.ToLower(uname)}
|
||||
}
|
||||
|
||||
has, err := orm.Get(u)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
} else if !has {
|
||||
return nil, ErrUserNotExist
|
||||
}
|
||||
|
||||
newUser := &User{Passwd: passwd, Salt: user.Salt}
|
||||
newUser := &User{Passwd: passwd, Salt: u.Salt}
|
||||
newUser.EncodePasswd()
|
||||
if user.Passwd != newUser.Passwd {
|
||||
if u.Passwd != newUser.Passwd {
|
||||
return nil, ErrUserNotExist
|
||||
}
|
||||
return &user, nil
|
||||
return u, nil
|
||||
}
|
||||
|
||||
// Follow is connection request for receiving user notifycation.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue