diff --git a/GitCandy/Controllers/AccountController.cs b/GitCandy/Controllers/AccountController.cs
index 66aab41..ade8cfa 100644
--- a/GitCandy/Controllers/AccountController.cs
+++ b/GitCandy/Controllers/AccountController.cs
@@ -53,7 +53,7 @@ namespace GitCandy.Controllers
return RedirectToAction("Detail", "Account", new { name = user.Name });
}
var auth = MembershipService.CreateAuthorization(user.ID, Token.AuthorizationExpires, Request.UserHostAddress);
- Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsSystemAdministrator);
+ Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsAdmin);
return RedirectToStartPage();
}
if (badName)
@@ -101,7 +101,7 @@ namespace GitCandy.Controllers
if (user != null)
{
var auth = MembershipService.CreateAuthorization(user.ID, Token.AuthorizationExpires, Request.UserHostAddress);
- Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsSystemAdministrator);
+ Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsAdmin);
return RedirectToStartPage(returnUrl);
}
@@ -135,7 +135,7 @@ namespace GitCandy.Controllers
if (!isAdmin)
{
var auth = MembershipService.CreateAuthorization(user.ID, Token.AuthorizationExpires, Request.UserHostAddress);
- Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsSystemAdministrator);
+ Token = new Token(auth.AuthCode, user.ID, user.Name, user.Nickname, user.IsAdmin);
}
return RedirectToAction("Detail", "Account", new { name });
diff --git a/GitCandy/Data/MembershipService.cs b/GitCandy/Data/MembershipService.cs
index a800100..bbd0e73 100644
--- a/GitCandy/Data/MembershipService.cs
+++ b/GitCandy/Data/MembershipService.cs
@@ -1,11 +1,13 @@
-using GitCandy.Base;
-using GitCandy.DAL;
+using System;
+using System.Composition;
+using System.Linq;
+using GitCandy.Base;
using GitCandy.Models;
using GitCandy.Security;
using GitCandy.Ssh;
-using System;
-using System.Composition;
-using System.Linq;
+using NewLife.Data;
+using NewLife.GitCandy.Entity;
+using NewLife.Web;
namespace GitCandy.Data
{
@@ -18,298 +20,280 @@ namespace GitCandy.Data
badName = false;
badEmail = false;
- using (var ctx = new GitCandyContext())
- //using (TransactionScope transaction = new TransactionScope()) // I don't know why Sqlite not support for TransactionScope
+ var user = User.FindByName(name);
+ if (user != null)
{
- try
- {
- var list = ctx.Users.Where(s => s.Name == name || s.Email == email).ToList();
- badName = list.Any(s => string.Equals(s.Name, name, StringComparison.OrdinalIgnoreCase));
- badEmail = list.Any(s => string.Equals(s.Email, email, StringComparison.OrdinalIgnoreCase));
-
- if (badName || badEmail)
- return null;
+ badName = true;
+ return null;
+ }
- var user = new User
- {
- Name = name,
- Nickname = nickname,
- Email = email,
- PasswordVersion = -1,
- Password = "",
- Description = description,
- CreationDate = DateTime.UtcNow,
- };
- ctx.Users.Add(user);
- ctx.SaveChanges();
+ user = User.FindByName(email);
+ if (user != null)
+ {
+ badEmail = true;
+ return null;
+ }
- using (var pp = PasswordProviderPool.Take())
- {
- user.PasswordVersion = pp.Version;
- user.Password = pp.Compute(user.ID, name, password);
- }
- ctx.SaveChanges();
- //transaction.Complete();
- return user;
- }
- catch
- {
- return null;
- }
+ user = new User
+ {
+ Name = name,
+ Nickname = nickname,
+ Email = email,
+ PasswordVersion = -1,
+ Password = "",
+ Description = description,
+ CreateTime = DateTime.Now,
+ };
+
+ using (var pp = PasswordProviderPool.Take())
+ {
+ user.PasswordVersion = pp.Version;
+ user.Password = pp.Compute(user.ID, name, password);
}
+
+ user.Save();
+
+ return user;
}
public UserModel GetUserModel(string name, bool withMembers = false, string viewUser = null)
{
- using (var ctx = new GitCandyContext())
- {
- var user = ctx.Users.FirstOrDefault(s => s.Name == name);
+ var user = User.FindByName(name);
+ if (user == null) return null;
- if (user == null)
- return null;
-
- var model = new UserModel
- {
- Name = user.Name,
- Nickname = user.Nickname,
- Email = user.Email,
- Description = user.Description,
- IsSystemAdministrator = user.IsSystemAdministrator,
- };
- if (withMembers)
+ var model = new UserModel
+ {
+ Name = user.Name,
+ Nickname = user.Nickname,
+ Email = user.Email,
+ Description = user.Description,
+ IsSystemAdministrator = user.IsAdmin,
+ };
+ if (withMembers)
+ {
+ model.Teams = user.TeamNames;
+ var rs = user.Repositories.Where(e => e.IsOwner);
+ if (!viewUser.IsNullOrEmpty())
{
- model.Teams = ctx.UserTeamRoles
- .Where(s => s.User.ID == user.ID)
- .Select(s => s.Team.Name)
- .AsEnumerable()
- .OrderBy(s => s, new StringLogicalComparer())
- .ToArray();
-
- model.Respositories = ctx.UserRepositoryRoles
- // belong user
- .Where(s => s.User.ID == user.ID && s.IsOwner)
- // can view for viewUser
- .Where(s => !s.Repository.IsPrivate
- || viewUser != null &&
- (ctx.Users.Any(t => t.Name == viewUser && t.IsSystemAdministrator)
- || ctx.UserRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
- && t.User.Name == viewUser
- && t.AllowRead)
- || ctx.TeamRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
- && t.Team.UserTeamRoles.Any(r => r.User.Name == viewUser)
- && t.AllowRead)))
- .Select(s => s.Repository.Name)
- .AsEnumerable()
- .OrderBy(s => s, new StringLogicalComparer())
- .ToArray();
+ var vu = User.FindByName(viewUser);
+ rs = rs.Where(e => e.Repository != null && e.Repository.CanViewFor(vu));
}
- return model;
+ model.Respositories = rs.Select(e => e.RepositoryName).OrderBy(e => e).ToArray();
+ //model.Respositories = ctx.UserRepositoryRoles
+ // // belong user
+ // .Where(s => s.User.ID == user.ID && s.IsOwner)
+ // // can view for viewUser
+ // .Where(s => !s.Repository.IsPrivate
+ // || viewUser != null &&
+ // (ctx.Users.Any(t => t.Name == viewUser && t.IsSystemAdministrator)
+ // || ctx.UserRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
+ // && t.User.Name == viewUser
+ // && t.AllowRead)
+ // || ctx.TeamRepositoryRoles.Any(t => t.RepositoryID == s.RepositoryID
+ // && t.Team.UserTeamRoles.Any(r => r.User.Name == viewUser)
+ // && t.AllowRead)))
+ // .Select(s => s.Repository.Name)
+ // .AsEnumerable()
+ // .OrderBy(s => s, new StringLogicalComparer())
+ // .ToArray();
}
+ return model;
}
public User Login(string id, string password)
{
- using (var ctx = new GitCandyContext())
+ var user = User.FindByName(id) ?? User.FindByEmail(id);
+ if (user != null)
{
- var user = ctx.Users.FirstOrDefault(s => s.Name == id || s.Email == id);
- if (user != null)
- {
- using (var pp1 = PasswordProviderPool.Take(user.PasswordVersion))
- if (user.Password == pp1.Compute(user.ID, user.Name, password))
- {
- if (user.PasswordVersion != PasswordProviderPool.LastVersion)
- using (var pp2 = PasswordProviderPool.Take())
- {
- user.Password = pp2.Compute(user.ID, user.Name, password);
- user.PasswordVersion = pp2.Version;
- ctx.SaveChanges();
- }
- return user;
- }
- }
- return null;
+ using (var pp1 = PasswordProviderPool.Take(user.PasswordVersion))
+ if (user.Password == pp1.Compute(user.ID, user.Name, password))
+ {
+ if (user.PasswordVersion != PasswordProviderPool.LastVersion)
+ using (var pp2 = PasswordProviderPool.Take())
+ {
+ user.Password = pp2.Compute(user.ID, user.Name, password);
+ user.PasswordVersion = pp2.Version;
+ user.Logins++;
+ user.LastLogin = DateTime.Now;
+ user.LastLoginIP = WebHelper.UserHost;
+ user.Save();
+ }
+ return user;
+ }
}
+ return null;
}
public void SetPassword(string name, string newPassword)
{
- using (var ctx = new GitCandyContext())
+ var user = User.FindByName(name);
+ if (user != null)
{
- var user = ctx.Users.FirstOrDefault(s => s.Name == name);
- if (user != null)
+ using (var pp = PasswordProviderPool.Take())
{
- using (var pp = PasswordProviderPool.Take())
- {
- user.Password = pp.Compute(user.ID, user.Name, newPassword);
- user.PasswordVersion = pp.Version;
- }
+ user.Password = pp.Compute(user.ID, user.Name, newPassword);
+ user.PasswordVersion = pp.Version;
+ }
- var auths = ctx.AuthorizationLogs.Where(s => s.UserID == user.ID);
- foreach (var auth in auths)
- {
- auth.IsValid = false;
- }
- ctx.SaveChanges();
+ var auths = AuthorizationLog.FindAllByUserID(user.ID);
+ foreach (var auth in auths)
+ {
+ auth.IsValid = false;
}
+ user.Save();
+ auths.Save();
}
}
public bool UpdateUser(UserModel model)
{
- using (var ctx = new GitCandyContext())
+ var user = User.FindByName(model.Name);
+ if (user != null)
{
- var user = ctx.Users.FirstOrDefault(s => s.Name == model.Name);
- if (user != null)
- {
- user.Nickname = model.Nickname;
- user.Email = model.Email;
- user.Description = model.Description;
- user.IsSystemAdministrator = model.IsSystemAdministrator;
+ user.Nickname = model.Nickname;
+ user.Email = model.Email;
+ user.Description = model.Description;
+ user.IsAdmin = model.IsSystemAdministrator;
- ctx.SaveChanges();
- return true;
- }
- return false;
+ user.Save();
+ return true;
}
+ return false;
}
public AuthorizationLog CreateAuthorization(long userID, DateTime expires, string ip)
{
- using (var ctx = new GitCandyContext())
+ var auth = new AuthorizationLog
{
- var auth = new AuthorizationLog
- {
- AuthCode = Guid.NewGuid(),
- UserID = userID,
- IssueDate = DateTime.Now,
- Expires = expires,
- IssueIp = ip,
- LastIp = ip,
- IsValid = true,
- };
- ctx.AuthorizationLogs.Add(auth);
- ctx.SaveChanges();
- return auth;
- }
+ AuthCode = Guid.NewGuid().ToString(),
+ UserID = (Int32)userID,
+ IssueDate = DateTime.Now,
+ Expires = expires,
+ IssueIp = ip,
+ LastIp = ip,
+ IsValid = true,
+ };
+ auth.Save();
+ return auth;
}
public Token GetToken(Guid authCode)
{
- using (var ctx = new GitCandyContext())
+ var auth = AuthorizationLog.FindByAuthCode(authCode + "");
+ if (auth == null) return null;
+
+ var user = auth.User;
+
+ return new Token(auth.AuthCode, auth.ID, user.Name, user.Nickname, user.IsAdmin, auth.Expires)
{
- var meta = ctx.AuthorizationLogs
- .Where(s => s.AuthCode == authCode && s.IsValid)
- .Select(s => new
- {
- s.AuthCode,
- s.Expires,
- s.User.ID,
- s.User.Name,
- s.User.Nickname,
- s.User.IsSystemAdministrator,
- s.LastIp,
- })
- .FirstOrDefault();
- return meta == null
- ? null
- : new Token(meta.AuthCode, meta.ID, meta.Name, meta.Nickname, meta.IsSystemAdministrator, meta.Expires)
- {
- LastIp = meta.LastIp
- };
- }
+ LastIp = auth.LastIp
+ };
}
public void UpdateAuthorization(Guid authCode, DateTime expires, string lastIp)
{
- using (var ctx = new GitCandyContext())
+ var auth = AuthorizationLog.FindByAuthCode(authCode + "");
+ if (auth != null)
{
- var auth = ctx.AuthorizationLogs.FirstOrDefault(s => s.AuthCode == authCode);
- if (auth != null)
- {
- auth.Expires = expires;
- auth.LastIp = lastIp;
- ctx.SaveChanges();
- }
+ auth.Expires = expires;
+ auth.LastIp = lastIp;
+ auth.Save();
}
}
public void SetAuthorizationAsInvalid(Guid authCode)
{
- using (var ctx = new GitCandyContext())
+ var auth = AuthorizationLog.FindByAuthCode(authCode + "");
+ if (auth != null)
{
- var auth = ctx.AuthorizationLogs.FirstOrDefault(s => s.AuthCode == authCode);
- if (auth != null)
- {
- auth.IsValid = false;
- ctx.SaveChanges();
- }
+ auth.IsValid = false;
+ auth.Save();
}
}
public void DeleteUser(string name)
{
- using (var ctx = new GitCandyContext())
+ var user = User.FindByName(name);
+ if (user != null)
{
- var user = ctx.Users.FirstOrDefault(s => s.Name == name);
- if (user != null)
- {
- user.UserTeamRoles.Clear();
- user.UserRepositoryRoles.Clear();
- user.AuthorizationLogs.Clear();
- user.SshKeys.Clear();
- ctx.Users.Remove(user);
- ctx.SaveChanges();
- }
+ //user.UserTeamRoles.Clear();
+ //user.UserRepositoryRoles.Clear();
+ //user.AuthorizationLogs.Clear();
+ //user.SshKeys.Clear();
+
+ user.Delete();
}
}
public UserListModel GetUserList(string keyword, int page, int pagesize = 20)
{
- using (var ctx = new GitCandyContext())
- {
- var query = ctx.Users.AsQueryable();
- if (!string.IsNullOrEmpty(keyword))
- query = query.Where(s => s.Name.Contains(keyword)
- || s.Nickname.Contains(keyword)
- || s.Email.Contains(keyword)
- || s.Description.Contains(keyword));
- query = query.OrderBy(s => s.Name);
+ var p = new PageParameter();
+ p.PageIndex = page;
+ p.PageSize = pagesize;
+ var list = User.Search(keyword, p);
- var model = new UserListModel
+ return new UserListModel
+ {
+ Users = list.ToList().Select(e => new UserModel
{
- Users = query
- .Skip((page - 1) * pagesize)
- .Take(pagesize)
- .Select(user => new UserModel
- {
- Name = user.Name,
- Nickname = user.Nickname,
- Email = user.Email,
- Description = user.Description,
- IsSystemAdministrator = user.IsSystemAdministrator,
- })
- .ToArray(),
- CurrentPage = page,
- ItemCount = query.Count(),
- };
- return model;
- }
+ Name = e.Name,
+ Nickname = e.Nickname,
+ Email = e.Email,
+ Description = e.Description,
+ IsSystemAdministrator = e.IsAdmin,
+ }).ToArray(),
+ CurrentPage = page,
+ ItemCount = p.TotalCount
+ };
+
+ //using (var ctx = new GitCandyContext())
+ //{
+ // var query = ctx.Users.AsQueryable();
+ // if (!string.IsNullOrEmpty(keyword))
+ // query = query.Where(s => s.Name.Contains(keyword)
+ // || s.Nickname.Contains(keyword)
+ // || s.Email.Contains(keyword)
+ // || s.Description.Contains(keyword));
+ // query = query.OrderBy(s => s.Name);
+
+ // var model = new UserListModel
+ // {
+ // Users = query
+ // .Skip((page - 1) * pagesize)
+ // .Take(pagesize)
+ // .Select(user => new UserModel
+ // {
+ // Name = user.Name,
+ // Nickname = user.Nickname,
+ // Email = user.Email,
+ // Description = user.Description,
+ // IsSystemAdministrator = user.IsSystemAdministrator,
+ // })
+ // .ToArray(),
+ // CurrentPage = page,
+ // ItemCount = query.Count(),
+ // };
+ // return model;
+ //}
}
public string[] SearchUsers(string query)
{
- using (var ctx = new GitCandyContext())
- {
- var length = query.Length + 0.5;
- return ctx.Users
- .Where(s => s.Name.Contains(query))
- .OrderByDescending(s => length / s.Name.Length)
- .ThenBy(s => s.Name)
- .Take(10)
- .Select(s => s.Name)
- .ToArray();
- }
+ var list = User.FindAll(User._.Name.Contains(query), null, null, 0, 10);
+ return list.ToList().Select(e => e.Name).ToArray();
+
+ //using (var ctx = new GitCandyContext())
+ //{
+ // var length = query.Length + 0.5;
+ // return ctx.Users
+ // .Where(s => s.Name.Contains(query))
+ // .OrderByDescending(s => length / s.Name.Length)
+ // .ThenBy(s => s.Name)
+ // .Take(10)
+ // .Select(s => s.Name)
+ // .ToArray();
+ //}
}
public string AddSshKey(string name, string sshkey)
@@ -319,57 +303,68 @@ namespace GitCandy.Data
sshkey = seg[1];
var fingerprint = KeyUtils.GetFingerprint(sshkey);
- using (var ctx = new GitCandyContext())
+ var user = User.FindByName(name);
+ if (user == null) return null;
+
+ var key = new SshKey
{
- var user = ctx.Users.FirstOrDefault(s => s.Name == name);
- if (user == null)
- return null;
+ UserID = user.ID,
+ KeyType = type,
+ Fingerprint = fingerprint,
+ PublicKey = sshkey,
+ ImportData = DateTime.UtcNow,
+ LastUse = DateTime.UtcNow,
+ };
- var key = new SshKey
- {
- UserID = user.ID,
- KeyType = type,
- Fingerprint = fingerprint,
- PublicKey = sshkey,
- ImportData = DateTime.UtcNow,
- LastUse = DateTime.UtcNow,
- };
+ key.Save();
- ctx.SshKeys.Add(key);
- ctx.SaveChanges();
- }
return fingerprint;
}
public void DeleteSshKey(string name, string sshkey)
{
- using (var ctx = new GitCandyContext())
- {
- var key = ctx.SshKeys.FirstOrDefault(s => s.User.Name == name && s.Fingerprint == sshkey);
- ctx.SshKeys.Remove(key);
- ctx.SaveChanges();
- }
+ var user = User.FindByName(name);
+ if (user == null) return;
+
+ var key = SshKey.FindByUserID(user.ID);
+ if (key == null) return;
+
+ if (key.Fingerprint == sshkey) key.Delete();
+
+ //using (var ctx = new GitCandyContext())
+ //{
+ // var key = ctx.SshKeys.FirstOrDefault(s => s.User.Name == name && s.Fingerprint == sshkey);
+ // ctx.SshKeys.Remove(key);
+ // ctx.SaveChanges();
+ //}
}
public bool HasSshKey(string fingerprint)
{
- using (var ctx = new GitCandyContext())
- {
- return ctx.SshKeys.Any(s => s.Fingerprint == fingerprint);
- }
+ //using (var ctx = new GitCandyContext())
+ //{
+ // return ctx.SshKeys.Any(s => s.Fingerprint == fingerprint);
+ //}
+
+ return SshKey.FindCount(SshKey._.Fingerprint, fingerprint) > 0;
}
public SshModel GetSshList(string name)
{
- using (var ctx = new GitCandyContext())
- {
- var keys = ctx.SshKeys
- .Where(s => s.User.Name == name)
- .Select(s => new SshModel.SshKey { Name = s.Fingerprint })
- .ToArray();
+ //using (var ctx = new GitCandyContext())
+ //{
+ // var keys = ctx.SshKeys
+ // .Where(s => s.User.Name == name)
+ // .Select(s => new SshModel.SshKey { Name = s.Fingerprint })
+ // .ToArray();
- return new SshModel { Username = name, SshKeys = keys };
- }
+ // return new SshModel { Username = name, SshKeys = keys };
+ //}
+
+ var user = User.FindByName(name);
+ if (user == null) return null;
+
+ return new Models.SshModel { Username = user.Name, SshKeys = user.SshKeys.Select(s => new SshModel.SshKey { Name = s.Fingerprint }).ToArray() };
}
#endregion
@@ -378,53 +373,52 @@ namespace GitCandy.Data
{
badName = false;
- using (var ctx = new GitCandyContext())
- //using (TransactionScope transaction = new TransactionScope())
+ var team = Team.FindByName(name);
+ if (team != null)
{
- try
- {
- badName = ctx.Teams.Count(s => s.Name == name) != 0;
-
- if (badName)
- return null;
-
- var team = new Team
- {
- Name = name,
- Description = description,
- CreationDate = DateTime.UtcNow,
- };
- ctx.Teams.Add(team);
+ badName = true;
+ return null;
+ }
- if (managerID > 0)
- {
- team.UserTeamRoles.Add(new UserTeamRole { Team = team, UserID = managerID, IsAdministrator = true });
- }
- ctx.SaveChanges();
+ team = new Team
+ {
+ Name = name,
+ Description = description,
+ //CreationDate = DateTime.UtcNow,
+ };
+ team.Save();
- //transaction.Complete();
- return team;
- }
- catch
- {
- return null;
- }
+ if (managerID > 0)
+ {
+ UserTeam.Add((Int32)managerID, team.ID, true);
+ //team.UserTeamRoles.Add(new UserTeamRole { Team = team, UserID = managerID, IsAdministrator = true });
}
+ //ctx.SaveChanges();
+
+ return team;
}
public bool UpdateTeam(TeamModel model)
{
- using (var ctx = new GitCandyContext())
- {
- var team = ctx.Teams.FirstOrDefault(s => s.Name == model.Name);
- if (team != null)
- {
- team.Description = model.Description;
- ctx.SaveChanges();
- return true;
- }
- return false;
- }
+ //using (var ctx = new GitCandyContext())
+ //{
+ // var team = ctx.Teams.FirstOrDefault(s => s.Name == model.Name);
+ // if (team != null)
+ // {
+ // team.Description = model.Description;
+ // ctx.SaveChanges();
+ // return true;
+ // }
+ // return false;
+ //}
+
+ var team = Team.FindByName(model.Name);
+ if (team == null) return false;
+
+ team.Description = model.Description;
+ team.Save();
+
+ return true;
}
public TeamModel GetTeamModel(string name, bool withMembers = false, string viewUser = null)
diff --git a/GitCandy/Data/RepositoryService.cs b/GitCandy/Data/RepositoryService.cs
index 5760ea7..8b96201 100644
--- a/GitCandy/Data/RepositoryService.cs
+++ b/GitCandy/Data/RepositoryService.cs
@@ -1,10 +1,10 @@
-using GitCandy.Base;
-using GitCandy.DAL;
-using GitCandy.Models;
-using System;
+using System;
using System.Collections.Generic;
using System.Composition;
using System.Linq;
+using GitCandy.Base;
+using GitCandy.Models;
+using NewLife.GitCandy.Entity;
namespace GitCandy.Data
{
@@ -13,41 +13,39 @@ namespace GitCandy.Data
{
public Repository Create(RepositoryModel model, long managerID, out bool badName)
{
- using (var ctx = new GitCandyContext())
- //using (TransactionScope transaction = new TransactionScope())
+ badName = false;
+ var rp = Repository.FindByName(model.Name);
+ if (rp != null)
{
- badName = ctx.Repositories.Any(s => s.Name == model.Name);
- if (badName)
- return null;
+ badName = true;
+ return null;
+ }
- var repo = new Repository
+ rp = new Repository
+ {
+ Name = model.Name,
+ Description = model.Description,
+ CreateTime = DateTime.UtcNow,
+ IsPrivate = model.IsPrivate,
+ AllowAnonymousRead = model.AllowAnonymousRead,
+ AllowAnonymousWrite = model.AllowAnonymousWrite,
+ };
+ rp.Save();
+
+ if (managerID > 0)
+ {
+ var ur = new UserRepository
{
- Name = model.Name,
- Description = model.Description,
- CreationDate = DateTime.UtcNow,
- IsPrivate = model.IsPrivate,
- AllowAnonymousRead = model.AllowAnonymousRead,
- AllowAnonymousWrite = model.AllowAnonymousWrite,
+ RepositoryID = rp.ID,
+ UserID = (Int32)managerID,
+ IsOwner = true,
+ AllowRead = true,
+ AllowWrite = true
};
- ctx.Repositories.Add(repo);
- ctx.SaveChanges();
-
- if (managerID > 0)
- {
- repo.UserRepositoryRoles.Add(new UserRepositoryRole
- {
- Repository = repo,
- UserID = managerID,
- IsOwner = true,
- AllowRead = true,
- AllowWrite = true
- });
- }
- ctx.SaveChanges();
-
- //transaction.Complete();
- return repo;
+ ur.Save();
}
+
+ return rp;
}
public RepositoryModel GetRepositoryModel(string reponame, bool withShipment = false, string username = null)
@@ -153,7 +151,7 @@ namespace GitCandy.Data
}
}
- public UserRepositoryRole RepositoryAddUser(string reponame, string username)
+ public UserRepository RepositoryAddUser(string reponame, string username)
{
using (var ctx = new GitCandyContext())
{
@@ -166,7 +164,7 @@ namespace GitCandy.Data
if (pair == null)
return null;
- var role = new UserRepositoryRole
+ var role = new UserRepository
{
RepositoryID = pair.RepoID,
UserID = pair.UserID,
@@ -216,7 +214,7 @@ namespace GitCandy.Data
}
}
- public TeamRepositoryRole RepositoryAddTeam(string reponame, string teamname)
+ public TeamRepository RepositoryAddTeam(string reponame, string teamname)
{
using (var ctx = new GitCandyContext())
{
@@ -229,7 +227,7 @@ namespace GitCandy.Data
if (pair == null)
return null;
- var role = new TeamRepositoryRole
+ var role = new TeamRepository
{
RepositoryID = pair.RepoID,
TeamID = pair.TeamID,
@@ -396,10 +394,10 @@ namespace GitCandy.Data
private RepositoryModel[] ToRepositoryArray(IEnumerable<Repository> source)
{
return source.Select(s => new RepositoryModel
- {
- Name = s.Name,
- Description = s.Description,
- })
+ {
+ Name = s.Name,
+ Description = s.Description,
+ })
.ToArray();
}
}
diff --git "a/GitCandy/Entity/Entity/SSH\345\257\206\351\222\245.Biz.cs" "b/GitCandy/Entity/Entity/SSH\345\257\206\351\222\245.Biz.cs"
index fc8d148..8c2e072 100644
--- "a/GitCandy/Entity/Entity/SSH\345\257\206\351\222\245.Biz.cs"
+++ "b/GitCandy/Entity/Entity/SSH\345\257\206\351\222\245.Biz.cs"
@@ -106,7 +106,7 @@ namespace NewLife.GitCandy.Entity
/// <param name="userid">用户</param>
/// <returns></returns>
[DataObjectMethod(DataObjectMethodType.Select, false)]
- public static SshKey FindByUserID(Boolean userid)
+ public static SshKey FindByUserID(Int32 userid)
{
if (Meta.Count >= 1000)
return Find(__.UserID, userid);
diff --git "a/GitCandy/Entity/Entity/\344\273\223\345\272\223.cs" "b/GitCandy/Entity/Entity/\344\273\223\345\272\223.cs"
index 80a4134..c690316 100644
--- "a/GitCandy/Entity/Entity/\344\273\223\345\272\223.cs"
+++ "b/GitCandy/Entity/Entity/\344\273\223\345\272\223.cs"
@@ -89,12 +89,24 @@ namespace NewLife.GitCandy.Entity
set { if (OnPropertyChanging(__.AllowAnonymousWrite, value)) { _AllowAnonymousWrite = value; OnPropertyChanged(__.AllowAnonymousWrite); } }
}
+ private String _Description;
+ /// <summary>描述</summary>
+ [DisplayName("描述")]
+ [Description("描述")]
+ [DataObjectField(false, false, true, 500)]
+ [BindColumn(7, "Description", "描述", null, "nvarchar(500)", 0, 0, true)]
+ public virtual String Description
+ {
+ get { return _Description; }
+ set { if (OnPropertyChanging(__.Description, value)) { _Description = value; OnPropertyChanged(__.Description); } }
+ }
+
private Int32 _CreateUserID;
/// <summary>创建者</summary>
[DisplayName("创建者")]
[Description("创建者")]
[DataObjectField(false, false, true, 10)]
- [BindColumn(7, "CreateUserID", "创建者", null, "int", 10, 0, false)]
+ [BindColumn(8, "CreateUserID", "创建者", null, "int", 10, 0, false)]
public virtual Int32 CreateUserID
{
get { return _CreateUserID; }
@@ -106,7 +118,7 @@ namespace NewLife.GitCandy.Entity
[DisplayName("创建时间")]
[Description("创建时间")]
[DataObjectField(false, false, true, 3)]
- [BindColumn(8, "CreateTime", "创建时间", null, "datetime", 3, 0, false)]
+ [BindColumn(9, "CreateTime", "创建时间", null, "datetime", 3, 0, false)]
public virtual DateTime CreateTime
{
get { return _CreateTime; }
@@ -118,7 +130,7 @@ namespace NewLife.GitCandy.Entity
[DisplayName("创建地址")]
[Description("创建地址")]
[DataObjectField(false, false, true, 50)]
- [BindColumn(9, "CreateIP", "创建地址", null, "nvarchar(50)", 0, 0, true)]
+ [BindColumn(10, "CreateIP", "创建地址", null, "nvarchar(50)", 0, 0, true)]
public virtual String CreateIP
{
get { return _CreateIP; }
@@ -130,7 +142,7 @@ namespace NewLife.GitCandy.Entity
[DisplayName("更新者")]
[Description("更新者")]
[DataObjectField(false, false, true, 10)]
- [BindColumn(10, "UpdateUserID", "更新者", null, "int", 10, 0, false)]
+ [BindColumn(11, "UpdateUserID", "更新者", null, "int", 10, 0, false)]
public virtual Int32 UpdateUserID
{
get { return _UpdateUserID; }
@@ -142,7 +154,7 @@ namespace NewLife.GitCandy.Entity
[DisplayName("更新时间")]
[Description("更新时间")]
[DataObjectField(false, false, true, 3)]
- [BindColumn(11, "UpdateTime", "更新时间", null, "datetime", 3, 0, false)]
+ [BindColumn(12, "UpdateTime", "更新时间", null, "datetime", 3, 0, false)]
public virtual DateTime UpdateTime
{
get { return _UpdateTime; }
@@ -154,7 +166,7 @@ namespace NewLife.GitCandy.Entity
[DisplayName("更新地址")]
[Description("更新地址")]
[DataObjectField(false, false, true, 50)]
- [BindColumn(12, "UpdateIP", "更新地址", null, "nvarchar(50)", 0, 0, true)]
+ [BindColumn(13, "UpdateIP", "更新地址", null, "nvarchar(50)", 0, 0, true)]
public virtual String UpdateIP
{
get { return _UpdateIP; }
@@ -182,6 +194,7 @@ namespace NewLife.GitCandy.Entity
case __.IsPrivate : return _IsPrivate;
case __.AllowAnonymousRead : return _AllowAnonymousRead;
case __.AllowAnonymousWrite : return _AllowAnonymousWrite;
+ case __.Description : return _Description;
case __.CreateUserID : return _CreateUserID;
case __.CreateTime : return _CreateTime;
case __.CreateIP : return _CreateIP;
@@ -201,6 +214,7 @@ namespace NewLife.GitCandy.Entity
case __.IsPrivate : _IsPrivate = Convert.ToBoolean(value); break;
case __.AllowAnonymousRead : _AllowAnonymousRead = Convert.ToBoolean(value); break;
case __.AllowAnonymousWrite : _AllowAnonymousWrite = Convert.ToBoolean(value); break;
+ case __.Description : _Description = Convert.ToString(value); break;
case __.CreateUserID : _CreateUserID = Convert.ToInt32(value); break;
case __.CreateTime : _CreateTime = Convert.ToDateTime(value); break;
case __.CreateIP : _CreateIP = Convert.ToString(value); break;
@@ -235,6 +249,9 @@ namespace NewLife.GitCandy.Entity
///<summary>匿名写</summary>
public static readonly Field AllowAnonymousWrite = FindByName(__.AllowAnonymousWrite);
+ ///<summary>描述</summary>
+ public static readonly Field Description = FindByName(__.Description);
+
///<summary>创建者</summary>
public static readonly Field CreateUserID = FindByName(__.CreateUserID);
@@ -277,6 +294,9 @@ namespace NewLife.GitCandy.Entity
///<summary>匿名写</summary>
public const String AllowAnonymousWrite = "AllowAnonymousWrite";
+ ///<summary>描述</summary>
+ public const String Description = "Description";
+
///<summary>创建者</summary>
public const String CreateUserID = "CreateUserID";
@@ -321,6 +341,9 @@ namespace NewLife.GitCandy.Entity
/// <summary>匿名写</summary>
Boolean AllowAnonymousWrite { get; set; }
+ /// <summary>描述</summary>
+ String Description { get; set; }
+
/// <summary>创建者</summary>
Int32 CreateUserID { get; set; }
diff --git "a/GitCandy/Entity/Entity/\345\233\242\351\230\237.cs" "b/GitCandy/Entity/Entity/\345\233\242\351\230\237.cs"
index 01d8c64..c1271d2 100644
--- "a/GitCandy/Entity/Entity/\345\233\242\351\230\237.cs"
+++ "b/GitCandy/Entity/Entity/\345\233\242\351\230\237.cs"
@@ -41,16 +41,16 @@ namespace NewLife.GitCandy.Entity
set { if (OnPropertyChanging(__.Name, value)) { _Name = value; OnPropertyChanged(__.Name); } }
}
- private String _Remark;
- /// <summary>备注</summary>
- [DisplayName("备注")]
- [Description("备注")]
- [DataObjectField(false, false, true, 50)]
- [BindColumn(3, "Remark", "备注", null, "nvarchar(50)", 0, 0, true)]
- public virtual String Remark
+ private String _Description;
+ /// <summary>描述</summary>
+ [DisplayName("描述")]
+ [Description("描述")]
+ [DataObjectField(false, false, true, 500)]
+ [BindColumn(3, "Description", "描述", null, "nvarchar(500)", 0, 0, true)]
+ public virtual String Description
{
- get { return _Remark; }
- set { if (OnPropertyChanging(__.Remark, value)) { _Remark = value; OnPropertyChanged(__.Remark); } }
+ get { return _Description; }
+ set { if (OnPropertyChanging(__.Description, value)) { _Description = value; OnPropertyChanged(__.Description); } }
}
private Int32 _CreateUserID;
@@ -142,7 +142,7 @@ namespace NewLife.GitCandy.Entity
{
case __.ID : return _ID;
case __.Name : return _Name;
- case __.Remark : return _Remark;
+ case __.Description : return _Description;
case __.CreateUserID : return _CreateUserID;
case __.CreateTime : return _CreateTime;
case __.CreateIP : return _CreateIP;
@@ -158,7 +158,7 @@ namespace NewLife.GitCandy.Entity
{
case __.ID : _ID = Convert.ToInt32(value); break;
case __.Name : _Name = Convert.ToString(value); break;
- case __.Remark : _Remark = Convert.ToString(value); break;
+ case __.Description : _Description = Convert.ToString(value); break;
case __.CreateUserID : _CreateUserID = Convert.ToInt32(value); break;
case __.CreateTime : _CreateTime = Convert.ToDateTime(value); break;
case __.CreateIP : _CreateIP = Convert.ToString(value); break;
@@ -181,8 +181,8 @@ namespace NewLife.GitCandy.Entity
///<summary>名称</summary>
public static readonly Field Name = FindByName(__.Name);
- ///<summary>备注</summary>
- public static readonly Field Remark = FindByName(__.Remark);
+ ///<summary>描述</summary>
+ public static readonly Field Description = FindByName(__.Description);
///<summary>创建者</summary>
public static readonly Field CreateUserID = FindByName(__.CreateUserID);
@@ -214,8 +214,8 @@ namespace NewLife.GitCandy.Entity
///<summary>名称</summary>
public const String Name = "Name";
- ///<summary>备注</summary>
- public const String Remark = "Remark";
+ ///<summary>描述</summary>
+ public const String Description = "Description";
///<summary>创建者</summary>
public const String CreateUserID = "CreateUserID";
@@ -249,8 +249,8 @@ namespace NewLife.GitCandy.Entity
/// <summary>名称</summary>
String Name { get; set; }
- /// <summary>备注</summary>
- String Remark { get; set; }
+ /// <summary>描述</summary>
+ String Description { get; set; }
/// <summary>创建者</summary>
Int32 CreateUserID { get; set; }
diff --git "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs" "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
index fc32712..fbf19ca 100644
--- "a/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
+++ "b/GitCandy/Entity/Entity/\347\224\250\346\210\267.Biz.cs"
@@ -134,6 +134,23 @@ namespace NewLife.GitCandy.Entity
}
public String[] RepositoryNames { get { return Repositories?.Select(e => e.RepositoryName).ToArray(); } }
+
+ private List<SshKey> _SshKeys;
+ /// <summary>绑定信息</summary>
+ public List<SshKey> SshKeys
+ {
+ get
+ {
+ if (_SshKeys == null && !Dirtys.ContainsKey("SshKeys"))
+ {
+ _SshKeys = SshKey.FindAllByUserID(ID);
+
+ Dirtys["SshKeys"] = true;
+ }
+ return _SshKeys;
+ }
+ set { _SshKeys = value; }
+ }
#endregion
#region 扩展查询
diff --git "a/GitCandy/Entity/Entity/\347\224\250\346\210\267\345\233\242\351\230\237.Biz.cs" "b/GitCandy/Entity/Entity/\347\224\250\346\210\267\345\233\242\351\230\237.Biz.cs"
index 5242360..3b7ad7c 100644
--- "a/GitCandy/Entity/Entity/\347\224\250\346\210\267\345\233\242\351\230\237.Biz.cs"
+++ "b/GitCandy/Entity/Entity/\347\224\250\346\210\267\345\233\242\351\230\237.Biz.cs"
@@ -4,14 +4,14 @@
* 时间:2016-11-21 15:48:51
* 版权:版权所有 (C) 新生命开发团队 2002~2016
*/
-using System;
+using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Xml.Serialization;
using NewLife.Log;
using NewLife.Web;
-using NewLife.Data;
+using NewLife.Data;
using XCode;
using XCode.Configuration;
using XCode.Membership;
@@ -22,14 +22,14 @@ namespace NewLife.GitCandy.Entity
public partial class UserTeam : Entity<UserTeam>
{
#region 对象操作
-
+
/// <summary>验证数据,通过抛出异常的方式提示验证失败。</summary>
/// <param name="isNew"></param>
public override void Valid(Boolean isNew)
{
- // 如果没有脏数据,则不需要进行任何处理
- if (!HasDirty) return;
+ // 如果没有脏数据,则不需要进行任何处理
+ if (!HasDirty) return;
// 这里验证参数范围,建议抛出参数异常,指定参数名,前端用户界面可以捕获参数异常并聚焦到对应的参数输入框
//if (String.IsNullOrEmpty(Name)) throw new ArgumentNullException(_.Name, _.Name.DisplayName + "无效!");
@@ -40,7 +40,7 @@ namespace NewLife.GitCandy.Entity
// 在新插入数据或者修改了指定字段时进行唯一性验证,CheckExist内部抛出参数异常
//if (isNew || Dirtys[__.Name]) CheckExist(__.Name);
-
+
// 处理当前已登录用户信息
if (!Dirtys[__.UserID] && ManageProvider.Provider.Current != null) UserID = (Int32)ManageProvider.Provider.Current.ID;
if (isNew && !Dirtys[__.CreateTime]) CreateTime = DateTime.Now;
@@ -170,6 +170,17 @@ namespace NewLife.GitCandy.Entity
#endregion
#region 业务
+ public static UserTeam Add(Int32 userid, Int32 teamid, Boolean isadmin)
+ {
+ var ut = FindByUserIDAndTeamID(userid, teamid);
+ if (ut == null) ut = new UserTeam();
+ ut.UserID = userid;
+ ut.TeamID = teamid;
+ ut.IsAdministrator = isadmin;
+ ut.Save();
+
+ return ut;
+ }
#endregion
}
}
\ No newline at end of file
diff --git "a/GitCandy/Entity/GitCandy\346\225\260\346\215\256\345\255\227\345\205\270.htm" "b/GitCandy/Entity/GitCandy\346\225\260\346\215\256\345\255\227\345\205\270.htm"
index d11cb6f..c540fe4 100644
--- "a/GitCandy/Entity/GitCandy\346\225\260\346\215\256\345\255\227\345\205\270.htm"
+++ "b/GitCandy/Entity/GitCandy\346\225\260\346\215\256\345\255\227\345\205\270.htm"
@@ -13,7 +13,7 @@
}
-->
</style>
-由Stone/X2生成于:2016-11-21 16:35:51 <BR />
+由Stone/X2生成于:2016-11-21 16:45:36 <BR />
User:
<strong>用户 (User)</strong> <BR>
@@ -300,11 +300,11 @@ Team:
<td> </td>
</tr>
<tr class="dbbody">
- <td>备注 </td>
- <td>Remark</td>
- <td>Remark</td>
+ <td>描述 </td>
+ <td>Description</td>
+ <td>Description</td>
<td>String</td>
- <td>50</td>
+ <td>500</td>
<td align="center"> </td>
<td align="center"> </td>
<td align="center"> </td>
@@ -473,6 +473,18 @@ Repository:
<td> </td>
</tr>
<tr class="dbbody">
+ <td>描述 </td>
+ <td>Description</td>
+ <td>Description</td>
+ <td>String</td>
+ <td>500</td>
+ <td align="center"> </td>
+ <td align="center"> </td>
+ <td align="center"> </td>
+ <td> </td>
+ <td> </td>
+ </tr>
+ <tr class="dbbody">
<td>创建者 </td>
<td>CreateUserID</td>
<td>CreateUserID</td>
diff --git a/GitCandy/Entity/NewLife.GitCandy.xml b/GitCandy/Entity/NewLife.GitCandy.xml
index 846f6d0..44ba245 100644
--- a/GitCandy/Entity/NewLife.GitCandy.xml
+++ b/GitCandy/Entity/NewLife.GitCandy.xml
@@ -30,7 +30,7 @@
<Columns>
<Column Name="ID" DataType="Int32" Identity="True" PrimaryKey="True" Description="编号" />
<Column Name="Name" DataType="String" Master="True" Description="名称" />
- <Column Name="Remark" DataType="String" Description="备注" />
+ <Column Name="Description" DataType="String" Length="500" Description="描述" />
<Column Name="CreateUserID" DataType="Int32" Description="创建者" />
<Column Name="CreateTime" DataType="DateTime" Description="创建时间" />
<Column Name="CreateIP" DataType="String" Description="创建地址" />
@@ -50,6 +50,7 @@
<Column Name="IsPrivate" DataType="Boolean" Description="私有" />
<Column Name="AllowAnonymousRead" DataType="Boolean" Description="匿名读" />
<Column Name="AllowAnonymousWrite" DataType="Boolean" Description="匿名写" />
+ <Column Name="Description" DataType="String" Length="500" Description="描述" />
<Column Name="CreateUserID" DataType="Int32" Description="创建者" />
<Column Name="CreateTime" DataType="DateTime" Description="创建时间" />
<Column Name="CreateIP" DataType="String" Description="创建地址" />
@@ -155,6 +156,7 @@
</Columns>
<Indexes>
<Index Columns="UserID" Unique="True" />
+ <Index Columns="Fingerprint" />
</Indexes>
</Table>
</Tables>
\ No newline at end of file
diff --git a/GitCandy/GitCandy.csproj b/GitCandy/GitCandy.csproj
index 75c5445..7e6cd96 100644
--- a/GitCandy/GitCandy.csproj
+++ b/GitCandy/GitCandy.csproj
@@ -161,6 +161,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
+ <Content Include="Entity\GitCandy数据字典.htm" />
<Content Include="Entity\XCoder.log">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -187,7 +188,7 @@
<Content Include="CustomErrors\401.html" />
<Content Include="CustomErrors\404.html" />
<Content Include="CustomErrors\500.html" />
- <Content Include="Entity\GitCandy.xml" />
+ <Content Include="Entity\NewLife.GitCandy.xml" />
<Content Include="Entity\XCoder.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>XCoder.log</LastGenOutput>
@@ -301,25 +302,24 @@
<Compile Include="Controllers\RepositoryController.cs" />
<Compile Include="Controllers\SettingController.cs" />
<Compile Include="Controllers\TeamController.cs" />
- <Compile Include="DAL\AuthorizationLog.cs" />
- <Compile Include="DAL\GitCandyContext.cs" />
- <Compile Include="DAL\Mapping\AuthorizationLogMap.cs" />
- <Compile Include="DAL\Mapping\RepositoryMap.cs" />
- <Compile Include="DAL\Mapping\SshKeyMap.cs" />
- <Compile Include="DAL\Mapping\TeamMap.cs" />
- <Compile Include="DAL\Mapping\TeamRepositoryRoleMap.cs" />
- <Compile Include="DAL\Mapping\UserMap.cs" />
- <Compile Include="DAL\Mapping\UserRepositoryRoleMap.cs" />
- <Compile Include="DAL\Mapping\UserTeamRoleMap.cs" />
- <Compile Include="DAL\Repository.cs" />
- <Compile Include="DAL\SshKey.cs" />
- <Compile Include="DAL\Team.cs" />
- <Compile Include="DAL\TeamRepositoryRole.cs" />
- <Compile Include="DAL\User.cs" />
- <Compile Include="DAL\UserRepositoryRole.cs" />
- <Compile Include="DAL\UserTeamRole.cs" />
<Compile Include="Data\MembershipService.cs" />
<Compile Include="Data\RepositoryService.cs" />
+ <Compile Include="Entity\Entity\SSH密钥.Biz.cs" />
+ <Compile Include="Entity\Entity\SSH密钥.cs" />
+ <Compile Include="Entity\Entity\仓库.Biz.cs" />
+ <Compile Include="Entity\Entity\仓库.cs" />
+ <Compile Include="Entity\Entity\团队.Biz.cs" />
+ <Compile Include="Entity\Entity\团队.cs" />
+ <Compile Include="Entity\Entity\团队仓库.Biz.cs" />
+ <Compile Include="Entity\Entity\团队仓库.cs" />
+ <Compile Include="Entity\Entity\用户.Biz.cs" />
+ <Compile Include="Entity\Entity\用户.cs" />
+ <Compile Include="Entity\Entity\用户仓库.Biz.cs" />
+ <Compile Include="Entity\Entity\用户仓库.cs" />
+ <Compile Include="Entity\Entity\用户团队.Biz.cs" />
+ <Compile Include="Entity\Entity\用户团队.cs" />
+ <Compile Include="Entity\Entity\认证日志.Biz.cs" />
+ <Compile Include="Entity\Entity\认证日志.cs" />
<Compile Include="Extensions\CommitLogExtension.cs" />
<Compile Include="Extensions\HtmlHelperExtension.cs" />
<Compile Include="Extensions\MetadataExtension.cs" />
diff --git a/GitCandy/Security/Token.cs b/GitCandy/Security/Token.cs
index 2da7cf8..254973b 100644
--- a/GitCandy/Security/Token.cs
+++ b/GitCandy/Security/Token.cs
@@ -11,9 +11,9 @@ namespace GitCandy.Security
private Token() { }
- public Token(Guid authCode, long userID, string username, string nickname, bool isSystemAdministrator, DateTime? expires = null)
+ public Token(String authCode, long userID, string username, string nickname, bool isSystemAdministrator, DateTime? expires = null)
{
- AuthCode = authCode;
+ AuthCode = new Guid(authCode);
UserID = userID;
Username = username;
Nickname = nickname;