public UserPhone RegisterByPhoneNumber(string phoneNumber, string password) { var userId = Guid.NewGuid().ToString("N"); var user = new User() { Id = userId, Province = string.Empty, Birthday = string.Empty, City = string.Empty, Country = string.Empty, Distinct = string.Empty, Name = phoneNumber, NickName = phoneNumber, Gender = GenderType.Unkonw, IsConfirmed = false, Grade = GradeType.Crystal, IsLocked = false, IsLunarBirthday = false, LockedTime = null, UserName = phoneNumber, Password = Cryptor.EncryptMD5(password), Roles = string.Empty, }; var userPhone = new UserPhone() { ValidateTime = DateTime.UtcNow, UserID = userId, PhoneNumber = phoneNumber, Type = PhoneType.MobilePhone, IsConfirmed = false, ValidateCode = ValidateCodeGenerator.CreateRandomCode(6), }; db.Entity <User>().Insert(user); db.Entity <UserPhone>().Insert(userPhone); return(userPhone); }
public virtual UserEmail RegisterByEmail(string email, string password) { var userId = Guid.NewGuid().ToString("N"); var user = new User() { Id = userId, Province = string.Empty, Birthday = string.Empty, City = string.Empty, Country = string.Empty, Distinct = string.Empty, Name = email, NickName = email, Gender = GenderType.Unkonw, IsConfirmed = false, Grade = GradeType.Crystal, IsLocked = false, IsLunarBirthday = false, LockedTime = null, UserName = email, Password = Cryptor.EncryptMD5(password), Roles = string.Empty, }; var userEmail = new UserEmail() { ValidateTime = DateTime.UtcNow, UserID = userId, Email = email, IsConfirmed = false, ValidateCode = ValidateCodeGenerator.CreateRandomCode(6), }; db.Entity <User>().Insert(user); db.Entity <UserEmail>().Insert(userEmail); return(userEmail); }
private Result <UserProfile> MobileLogin(string phoneNumber, string password, string code) { var userPhone = db.Entity <UserPhone>().Query().Where(m => m.PhoneNumber == phoneNumber).FirstOrDefault(); User user; if (userPhone == null) { var userId = Guid.NewGuid().ToString("N"); user = new User() { Id = userId, Province = string.Empty, Birthday = string.Empty, City = string.Empty, Country = string.Empty, Distinct = string.Empty, Name = phoneNumber, NickName = phoneNumber, Gender = GenderType.Unkonw, IsConfirmed = false, Grade = GradeType.Crystal, IsLocked = false, IsLunarBirthday = false, LockedTime = null, UserName = phoneNumber, Password = Cryptor.EncryptMD5(password), Roles = string.Empty, }; userPhone = new UserPhone() { ValidateTime = DateTime.UtcNow, UserID = userId, PhoneNumber = phoneNumber, Type = PhoneType.MobilePhone, IsConfirmed = false, ValidateCode = ValidateCodeGenerator.CreateRandomCode(6), }; db.Entity <User>().Insert(user); db.Entity <UserPhone>().Insert(userPhone); return(Result <UserProfile> .Success(new UserProfile() { Id = user.Id, Language = user.Language, Birthday = user.Birthday, City = user.City, Country = user.Country, Distinct = user.Distinct, Gender = user.Gender, IsConfirmed = user.IsConfirmed, IsLocked = user.IsLocked, IsLunarBirthday = user.IsLunarBirthday, LockedTime = user.LockedTime, Name = user.Name, NickName = user.NickName, Province = user.Province, UserName = user.UserName, Roles = user.Roles.Split(';', ',', '|'), })); } user = db.Entity <User>().Query().Where(m => m.Id == userPhone.UserID && !m.IsLocked).FirstOrDefault(); if (user == null) { return(Result <UserProfile> .Fail(ResultCode.Error)); } if (Cryptor.EncryptMD5(password) == user.Password) { return(Result <UserProfile> .Success(new UserProfile() { Id = user.Id, Language = user.Language, Birthday = user.Birthday, City = user.City, Country = user.Country, Distinct = user.Distinct, Gender = user.Gender, IsConfirmed = user.IsConfirmed, IsLocked = user.IsLocked, IsLunarBirthday = user.IsLunarBirthday, LockedTime = user.LockedTime, Name = user.Name, NickName = user.NickName, Province = user.Province, UserName = user.UserName, Roles = user.Roles.Split(';', ',', '|'), })); } return(Result <UserProfile> .Fail(ResultCode.Error)); }