/// <summary>
 /// Deprecated Method for adding a new object to the ApiKeys EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToApiKeys(ApiKey apiKey)
 {
     base.AddObject("ApiKeys", apiKey);
 }
 /// <summary>
 /// Create a new ApiKey object.
 /// </summary>
 /// <param name="apiKeyId">Initial value of the ApiKeyId property.</param>
 public static ApiKey CreateApiKey(global::System.Guid apiKeyId)
 {
     ApiKey apiKey = new ApiKey();
     apiKey.ApiKeyId = apiKeyId;
     return apiKey;
 }
Beispiel #3
0
        public Status<Guid> GetAuthToken(ApiKey apiKey, string affiliateUserKey,
            string email, string passwordHash,
            string firstName, string lastName, string username)
        {
            RedisPublisher.Publish("token","Getting token for api key: " + apiKey.ToString());

            //check if user exists
            var userId = accountAdapter.GetAffiliateUserIdByUsernameOrEmailAndApiKey(email, apiKey.ApiKeyId);

            //did we not find anything?
            if (userId.StatusCode == 404)
            {
                //try again, looking for regular rentler users this time
                userId = accountAdapter.GetUserIdByUsernameOrEmail(email);

                //still didn't find anything?
                if (userId.StatusCode == 404)
                {
                    //we've got a new one, make 'em
                    var user = new User();
                    user.Email = email;
                    user.FirstName = firstName;
                    user.LastName = lastName ?? string.Empty;
                    user.Username = username;
                    user.PasswordHash = string.Empty;
                    user.CreateDateUtc = DateTime.UtcNow;
                    user.UpdatedBy = "ksl auth";
                    user.UpdateDateUtc = DateTime.UtcNow;

                    var status = Status.Validatate<User>(user);

                    if (status.StatusCode != 200)
                    {
                        var result = Status.NotFound<Guid>();
                        result.Errors = status.Errors;

                        return result;
                    }

                    using (var context = new RentlerContext())
                    {
                        context.Users.Add(user);
                        context.SaveChanges();
                        userId = Status.OK(user.UserId);
                    }
                }

                //Okay, now they're either already a Rentler user but are coming in from an affiliate,
                //or they just became one from an affiliate, so create an affiliate user for them.
                using (var context = new RentlerContext())
                {
                    var affiliate = new AffiliateUser();
                    affiliate.UserId = userId.Result;
                    affiliate.AffiliateUserKey = affiliateUserKey;
                    affiliate.ApiKey = apiKey.ApiKeyId;
                    affiliate.PasswordHash = passwordHash;
                    context.AffiliateUsers.Add(affiliate);
                    context.SaveChanges();
                }
            }

            //generate auth token
            var token = CreateAuthToken(userId.Result);

            RedisPublisher.Publish("token", "Returning token: " + token.ToString());

            //return token
            return Status.OK(token);
        }