Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }