feat: IUser 增加手机登录逻辑

This commit is contained in:
Argo-Tianyi 2021-12-23 12:35:37 +08:00
parent 9ed1fd8f20
commit 4b6b1e2d6e
2 changed files with 52 additions and 0 deletions

View File

@ -126,4 +126,47 @@ class UserService : BaseDatabase, IUser
}
return ret;
}
/// <summary>
///
/// </summary>
/// <param name="phone"></param>
/// <param name="appId"></param>
/// <param name="roles"></param>
/// <returns></returns>
public bool TryCreateUserByPhone(string phone, string appId, ICollection<string> roles)
{
var ret = false;
try
{
var user = GetAll().FirstOrDefault(user => user.UserName == phone);
if (user == null)
{
Database.BeginTransaction();
user = new User()
{
ApprovedBy = "Mobile",
ApprovedTime = DateTime.Now,
DisplayName = "手机用户",
UserName = phone,
Icon = "default.jpg",
Description = "手机用户",
App = appId
};
Database.Save(user);
// Authorization
var roleIds = Database.Fetch<string>("select ID from Roles where RoleName in (@roles)", new { roles });
Database.InsertBatch("UserRole", roleIds.Select(g => new { RoleID = g, UserID = user.Id }));
Database.CompleteTransaction();
}
ret = true;
}
catch (Exception)
{
Database.AbortTransaction();
throw;
}
return ret;
}
}

View File

@ -71,4 +71,13 @@ public interface IUser
/// <param name="password"></param>
/// <returns></returns>
bool Authenticate(string userName, string password);
/// <summary>
///
/// </summary>
/// <param name="phone"></param>
/// <param name="appId"></param>
/// <param name="roles"></param>
/// <returns></returns>
bool TryCreateUserByPhone(string phone, string appId, ICollection<string> roles);
}