Beispiel #1
0
        public User SignUp(string name, string loginTypeCode, string identifier, string secret)
        {
            User user = new User();

            user.Name    = name;
            user.Created = DateTime.Now;
            this.userRepository.Create(user);
            this.requestHandler.Storage.Save();

            CredentialType credentialType = this.credentialTypeRepository.WithCode(loginTypeCode);

            if (credentialType != null)
            {
                Credential credential = new Credential();

                credential.UserId           = user.Id;
                credential.CredentialTypeId = credentialType.Id;
                credential.Identifier       = identifier;
                credential.Secret           = string.IsNullOrEmpty(secret) ? null : MD5Hasher.ComputeHash(secret);
                this.credentialRepository.Create(credential);
                this.requestHandler.Storage.Save();
            }

            return(user);
        }
Beispiel #2
0
        public User Validate(string loginTypeCode, string identifier, string secret)
        {
            CredentialType credentialType = this.credentialTypeRepository.WithCode(loginTypeCode);

            if (credentialType == null)
            {
                return(null);
            }

            Credential login = this.credentialRepository.WithCredentialTypeIdAndIdentifierAndSecret(
                credentialType.Id, identifier, MD5Hasher.ComputeHash(secret)
                );

            if (login == null)
            {
                return(null);
            }

            return(this.userRepository.WithKey(login.UserId));
        }