Пример #1
0
        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);
        }
Пример #2
0
        public async Task <bool> Register(User user)
        {
            var registeredUser = await this.repository.GetAsync <User>(true, x => x.Email == user.Email);

            if (registeredUser != null)
            {
                throw new Exception("Email is already registered.");
            }

            user.Password = CryptographicService.GetHashString(user.Password);
            await this.repository.AddAsync <User>(user);

            return(true);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }
Пример #6
0
 public int GetInstitutionIdFromToken(string token)
 {
     return(Convert.ToInt32(CryptographicService.DecryptString(token).Split("|")[3]));
 }
Пример #7
0
 public int GetRecipientIdFromToken(string token)
 {
     return(Convert.ToInt32(CryptographicService.DecryptString(token).Split("|")[2]));
 }
Пример #8
0
 public int GetInitiatorIdFromToken(string token)
 {
     return(Convert.ToInt32(CryptographicService.DecryptString(token).Split("|")[1]));
 }
Пример #9
0
 public static string GetUserRole(string token)
 {
     return(CryptographicService.DecryptString(token).Split("|")[1]);
 }
Пример #10
0
 public static int GetUserId(string token)
 {
     return(Convert.ToInt32(CryptographicService.DecryptString(token).Split("|")[0]));
 }