public AccountSignResult CreateNew(ClientDevice entity) { var result = new AccountSignResult(); result.SignStatus = SignStatus.None; if (null == entity || string.IsNullOrEmpty(entity.DeviceKey) || string.IsNullOrEmpty(entity.Product) || string.IsNullOrEmpty(entity.Brand)) { this.ReturnPreconditionFailedMessage(); } var account = AccountAuthentication.CreateNew(entity); if (null != account) { result.SignStatus = SignStatus.Success; result.Account = new AccountEntity(account, null); WriteTokenToBrowser(result); } else { result.SignStatus = SignStatus.Error; } return(result); }
public ActionResult SignIn(string phone, string password) { if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(password)) { return(Json(new { Success = false, Message = "手机号和密码不能为空" })); } var entity = new AccountSign() { MobilePhone = phone, Password = password }; UserPassport userPassport = null; var success = AccountAuthentication.SignIn(phone, password, null, out userPassport); if (!success) { return(Json(new { Success = false, Message = "手机号或密码错误" })); } var account = AnonymousAccount.FindLastByPassport(userPassport.PassportId); if (account == null) { return(Json(new { Success = false, Message = "Token已失效" })); } CookieHelper.SetCookie(AccountAuthentication.TokenKey, account.Token.AccessToken); return(Json(new { Success = true, Message = "登陆成功" })); }
public AccountSignResult BindThirdPassport(ThirdPassport entity) { if (null == entity || string.IsNullOrEmpty(entity.Platform) || string.IsNullOrEmpty(entity.PlatformPassportId)) { return(null); } var account = MvcContext.Current.ClientAccount; if (null == account) { return(null); } var signStatus = SignStatus.Error; UserPassport userPassport = AccountAuthentication.BindThirdPassport(entity, out signStatus); var result = new AccountSignResult(); result.SignStatus = signStatus; if (result.SignStatus == SignStatus.Success) { result.Account = new AccountEntity(account, userPassport); WriteTokenToBrowser(result); } else { result.ErrorMessage = "绑定账号失败"; } return(result); }
public static ILifecycle Create(RpcEndPoint endPoint, IAccountLoginService accountLoginService) { var port = new ServerPort(endPoint.Host, endPoint.Port, ServerCredentials.Insecure); var controller = new RpcServiceController(port); controller.RegisterService(token => AccountAuthentication.BindService(new AccountAuthenticationService(accountLoginService, token))); return(controller); }
public AccountSignResult ShortcutSignIn(AccountSign entity) { if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) || string.IsNullOrEmpty(entity.ValidationCode)) { return(null); } var account = MvcContext.Current.ClientAccount; if (null == account) { return(null); } var passportId = UserPassport.FindIdByMobilePhone(entity.MobilePhone); if (passportId == 0) { entity.Password = HashHelper.ComputeHash(entity.MobilePhone, HashAlgorithmName.SHA1).Substring(0, 6); return(SignUp(entity)); } var isValid = MessageHelper.CheckSMSValidationCode(entity.MobilePhone, entity.ValidationCode); if (MvcContext.Current.Test && entity.ValidationCode == AppEnvironment.TestValidationCode) { isValid = true; } if (false == isValid) { return(new AccountSignResult() { SignStatus = SignStatus.InvalidValidationCode, ErrorMessage = "验证码无效,请重新获取" }); } if (!string.IsNullOrEmpty(entity.InviteCode)) { System.Web.HttpContext.Current.Items.Add(WorkplaceApplication.InviteCodeKey, entity.InviteCode); } UserPassport userPassport = null; var isSignIn = AccountAuthentication.SignIn(passportId, new SignedInLog(), out userPassport); var result = new AccountSignResult(); result.SignStatus = isSignIn ? SignStatus.Success : SignStatus.InvalidPassword; if (result.SignStatus == SignStatus.Success) { result.Account = new AccountEntity(account, userPassport); result.AdditionalAction = ProcessAdditionalAction(entity.AdditionalAction); WriteTokenToBrowser(result); } else { result.ErrorMessage = "用户名或密码错误"; } return(result); }
public AccountEntity ChangeCurrentToOrganizationProfile(OrganizationProfile newProfile) { var passport = MvcContext.Current.UserPassport; MemberShip.OpenOrganizationService(passport, newProfile); AccountAuthentication.SyncIMAccount(passport); return(new AccountEntity(MvcContext.Current.ClientAccount, passport)); }
/// <summary> /// /// </summary> /// <param name="account"></param> /// <param name="passport"></param> public AccountEntity(AnonymousAccount account, UserPassport passport) { this.SetPropertyValues(account.GetPropertyValues()); if (null != passport && null != passport.Profile) { this.UserProfile = passport.Profile; this.MobilePhone = passport.MobilePhone; this.MultipleProfiles = passport.MultipleProfiles; this.IMAccount = AccountAuthentication.LoadIMAccount(passport.Profile); } }
public AccountEntity ChangeToUser() { var passport = MvcContext.Current.UserPassport; AccountEntity result = null; if (passport.Profile is OrganizationProfile) { var profile = (passport.Profile as OrganizationProfile); profile.CurrentProfileType = ProfileType.UserProfile; var saved = profile.Save(); if (saved) { AccountAuthentication.SyncIMAccount(passport); result = new AccountEntity(MvcContext.Current.ClientAccount, passport); } } return(result); }
public bool ChangeProfile([FromBody] UserProfile entity) { if (entity == null) { return(false); } var profile = MvcContext.Current.UserPassport.Profile; var syncIMAccount = false == string.IsNullOrEmpty(entity.Nickname) && profile.Nickname != entity.Nickname; profile.FillPropertiesFromEntity(entity, true); profile.PassportId = MvcContext.Current.PassportId; var saved = profile.Save(); if (saved && syncIMAccount) { AccountAuthentication.SyncIMAccount(MvcContext.Current.UserPassport); } return(saved); }
public AccountEntity OpenOrganizationService([FromBody] OrganizationProfile entity) { var passport = MvcContext.Current.UserPassport; if (null == entity) { entity = new OrganizationProfile(); entity.PassportId = passport.PassportId; entity.RealName = passport.Profile.Nickname; } var success = MemberShip.OpenOrganizationService(passport, entity); AccountEntity result = null; if (success) { AccountAuthentication.SyncIMAccount(passport); result = new AccountEntity(MvcContext.Current.ClientAccount, passport); } return(result); }
public ActionResult LoadAccountInfo() { AccountEntity accountEntity = null; if (null != this.Request.UserAgent && null != this.Request.UrlReferrer) { var accessToken = CookieHelper.GetValue(AccountAuthentication.TokenKey); if (null == accessToken) { var device = new ClientDevice(); accountEntity = new AccountEntity(AccountAuthentication.CreateNew(device), null);; CookieHelper.SetCookie(AccountAuthentication.TokenKey, accountEntity.Token.AccessToken, DateTime.MaxValue); } else { accountEntity = new AccountEntity(MvcContext.Current.ClientAccount, MvcContext.Current.UserPassport); } } return(View("LoadAccountJS", accountEntity)); }
public AccountEntity ChangeCurrentToUserProfile() { var passport = MvcContext.Current.UserPassport; AccountEntity result = null; if ((passport.MultipleProfiles & ProfileType.UserProfile) != ProfileType.UserProfile) { passport.MultipleProfiles = passport.MultipleProfiles | ProfileType.UserProfile; passport.Save(); } if (passport.Profile.CurrentProfileType != ProfileType.UserProfile) { var profile = passport.Profile; profile.CurrentProfileType = ProfileType.UserProfile; var saved = profile.Save(); if (saved) { AccountAuthentication.SyncIMAccount(passport); result = new AccountEntity(MvcContext.Current.ClientAccount, passport); } } return(new AccountEntity(MvcContext.Current.ClientAccount, passport)); }
public AccountSignResult SignIn(AccountSign entity) { if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) || string.IsNullOrEmpty(entity.Password)) { return(null); } var account = MvcContext.Current.ClientAccount; if (null == account) { return(null); } if (!string.IsNullOrEmpty(entity.InviteCode)) { System.Web.HttpContext.Current.Items.Add(WorkplaceApplication.InviteCodeKey, entity.InviteCode); } UserPassport userPassport = null; var isSignIn = AccountAuthentication.SignIn(entity.MobilePhone, entity.Password, new SignedInLog(), out userPassport); var result = new AccountSignResult(); result.SignStatus = isSignIn ? SignStatus.Success : SignStatus.InvalidPassword; if (result.SignStatus == SignStatus.Success) { result.Account = new AccountEntity(account, userPassport); result.AdditionalAction = ProcessAdditionalAction(entity.AdditionalAction); WriteTokenToBrowser(result); } else { result.ErrorMessage = "用户名或密码错误"; } return(result); }
public AccountSignResult SignUp(AccountSign entity) { if (null == entity || string.IsNullOrEmpty(entity.MobilePhone) || string.IsNullOrEmpty(entity.Password) || string.IsNullOrEmpty(entity.ValidationCode) || ProfileType.None == entity.SelectedProfileType) { this.ReturnPreconditionFailedMessage(); } var account = MvcContext.Current.ClientAccount; if (null == account) { this.ReturnPreconditionFailedMessage(); } var isValid = MessageHelper.CheckSMSValidationCode(entity.MobilePhone, entity.ValidationCode); if (MvcContext.Current.Test && entity.ValidationCode == AppEnvironment.TestValidationCode) { isValid = true; } if (false == isValid) { return(new AccountSignResult() { SignStatus = SignStatus.InvalidValidationCode, ErrorMessage = "验证码无效,请重新获取" }); } if (!string.IsNullOrEmpty(entity.InviteCode)) { System.Web.HttpContext.Current.Items.Add(WorkplaceApplication.InviteCodeKey, entity.InviteCode); } var signStatus = SignStatus.Error; var signedUpInfo = new SignedUpInfo() { InviteCode = entity.InviteCode, SignedUpIp = this.Request.GetClientIP(), HttpUserAgent = this.Request.GetUserAgent(), HttpReferer = null == this.Request.Headers.Referrer ? "" : this.Request.Headers.Referrer.ToString() }; var userPassport = AccountAuthentication.SignUp(entity.MobilePhone, entity.Password, entity.SelectedProfileType, signedUpInfo, out signStatus); var result = new AccountSignResult(); result.SignStatus = signStatus; if (result.SignStatus == SignStatus.Success) { result.CreatedNewPassport = true; result.Account = new AccountEntity(account, userPassport); result.AdditionalAction = ProcessAdditionalAction(entity.AdditionalAction); WriteTokenToBrowser(result); } else { if (result.SignStatus == SignStatus.DuplicateMobilePhone) { result.ErrorMessage = "手机号已经注册"; } else { result.ErrorMessage = "注册失败"; } } return(result); }