/// <summary>
 /// Deprecated Method for adding a new object to the AffiliateUsers EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToAffiliateUsers(AffiliateUser affiliateUser)
 {
     base.AddObject("AffiliateUsers", affiliateUser);
 }
 /// <summary>
 /// Create a new AffiliateUser object.
 /// </summary>
 /// <param name="userId">Initial value of the UserId property.</param>
 /// <param name="apiKey">Initial value of the ApiKey property.</param>
 /// <param name="isDeleted">Initial value of the IsDeleted property.</param>
 public static AffiliateUser CreateAffiliateUser(global::System.Int32 userId, global::System.Guid apiKey, global::System.Boolean isDeleted)
 {
     AffiliateUser affiliateUser = new AffiliateUser();
     affiliateUser.UserId = userId;
     affiliateUser.ApiKey = apiKey;
     affiliateUser.IsDeleted = isDeleted;
     return affiliateUser;
 }
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);
        }