public async Task <HttpMessage <IdentityResult> > Login(LoginUser login) => await TryCatchResponseAsync(async() => { HttpMessage <UserWithRole> postResult = await Json.PostAsync <HttpMessage <UserWithRole>, LoginUser>(AppSettings.AccountService.Server, AppSettings.AccountService.ApiAccount + "/login", login, onError: (e) => { postResult = CreateResponseError <UserWithRole>(e); }); UserWithRole user = postResult?.Data; if (user == null) { throw new Exception("Невозможно произвести авторизацию!"); } Principal principal = new Principal(user); AuthUserManager.LogIn(principal); int siteUserId = SetUserUid(login.Uid, user.Id); bool Cms = user.Roles != null && user.Roles.Count > 0 && user.Roles.FirstOrDefault(f => f.Role == 1) != null; return(CreateResponseOk(new IdentityResult { SiteUserId = siteUserId, Auth = true, Cms = Cms, Token = principal.GetKey(), User = user })); });
public async Task <HttpMessage <UidResult> > Uid(string uid) => await TryCatchResponseAsync(async() => { return(await Task.Run(() => { Principal principal = Core.Http.HttpContext.Current.User as Principal; UserWithRole user = null; if (principal == null || principal.User == null) { UserUid uu = GetUserUid(uid); HttpMessage <UserWithRole> postResult = Json.Post <HttpMessage <UserWithRole>, UserUid>(AppSettings.AccountService.Server, AppSettings.AccountService.ApiAccount + "/loginCheck", uu); user = postResult?.Data; } else { user = (principal.User as UserWithRole); } if (principal == null && user != null && user.Id != 0) { principal = new Principal(user); AuthUserManager.LogIn(principal); } int userId = user.Id; int siteUserId = SetUserUid(uid, userId); bool Cms = user.Roles != null && user.Roles.Count > 0 && user.Roles.FirstOrDefault(f => f.Role == 1) != null; bool auth = user != null && user.Id != 0; string version = this.GetType().Assembly.GetCustomAttribute <AssemblyFileVersionAttribute>().Version; return CreateResponseOk(new UidResult() { Version = version, Identity = new IdentityResult { SiteUserId = siteUserId, Auth = auth, Cms = Cms, Token = principal == null ? "" : principal.GetKey(), User = user } }); })); });