public static UserInfo GetUserInfo(string userId, string userRole, string institutionId) { UserInfo result = new UserInfo { Role = userRole, InstitutionId = institutionId }; result.Token = CryptographicService.EncryptString(userId + "|" + userRole + "|" + institutionId); return(result); }
public async Task <UserInfo> LoginLikeClient(User user) { var client = await this.repository.GetAsync <User>(true, x => x.Email == user.Email && x.Password == CryptographicService.GetHashString(user.Password)); if (client == null) { throw new Exception("User not found"); } UserInfo userInfo = new UserInfo(); userInfo.Token = CryptographicService.EncryptString(client.Id + "|" + "user" + "|" + ""); userInfo.Role = "user"; userInfo.InstitutionId = "-1"; return(userInfo); }
public async Task <ChatTokenContainer> GetChatToken(ChatInfo сhatInfo) { var chat = await this.repository.GetAsync <Chat>(true, x => x.Id == сhatInfo.Id && x.InitiatorId == сhatInfo.InitiatorId && x.RecipientId == сhatInfo.RecipientId && x.InstitutionId == сhatInfo.InstitutionId); if (chat == null) { throw new Exception("Chat not found"); } ChatTokenContainer chatTokenContainer = new ChatTokenContainer(); chatTokenContainer.ChatToken = CryptographicService.EncryptString(chat.Id + "|" + chat.InitiatorId + "|" + chat.RecipientId + "|" + chat.InstitutionId); chatTokenContainer.ChatId = chat.Id; return(chatTokenContainer); }
public async Task <UserInfo> LoginLikeEmployee(UserInfo userInfo) { int clientId = AuthenticationService.GetUserId(userInfo.Token); var client = await this.repository.GetAsync <User>(true, x => x.Id == clientId); if (client == null) { throw new Exception("User not found"); } string role = userInfo.Role; string InstitutionId = userInfo.InstitutionId.ToString(); UserInfo newUserInfo = new UserInfo(); newUserInfo.Token = CryptographicService.EncryptString(clientId + "|" + role + "|" + InstitutionId); newUserInfo.Role = role; newUserInfo.InstitutionId = InstitutionId; return(newUserInfo); }