Esempio n. 1
0
 public bool CreateCustomerAccount(CustomerAccount_ToRemove user)
 {
     var repo = GoEatRepo.Instance;
     using (var db = repo.OpenConnectionFromPool())
     {
         return repo.CreateCustomerAccount(db, user);
     }
 }
Esempio n. 2
0
 public bool CreateCustomerAccount(IDbConnection db, CustomerAccount_ToRemove customerAccount)
 {
     string sqlString = "INSERT INTO customer_account " +
                                "(id" +
                                ",username" +
                                ",profile" +
                                ",created_at " +
                                ",session) " +
                          "VALUES (@id, @username, @profile, @created_at, @session)";
     return 1 == db.Execute(sqlString, new
     {
         customerAccount.id,
         customerAccount.username,
         customerAccount.profile,
         created_at = customerAccount.created_at.Date.ToString("yyyy-MM-dd HH:mm:ss"),
         customerAccount.session
     });
 }
Esempio n. 3
0
        /// <summary>
        /// Call login to Goplay API
        /// </summary>
        /// <param name="userName">user name</param>
        /// <param name="pwd">password</param>
        /// <param name="game_id">restaurant id</param>
        /// <returns>result</returns>
        public async Task<Result<LoginModel>> Login(string userName, string pwd, string game_id)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = Urls.GetBaseServerUri(); // TODO: Need a switch for live and debug server //
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));

                // HTTP POST
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("username", userName), 
                    new KeyValuePair<string, string>("password", pwd),
                    new KeyValuePair<string, string>("partner_id", Urls.PARTNER_ID)
                });

                HttpResponseMessage response = await client.PostAsync(Urls.ACTION_LOGIN, formContent);
                if (response.IsSuccessStatusCode)
                {
                    var customerLogin = JsonConvert.DeserializeObject<LoginModel>(await response.Content.ReadAsStringAsync());
                    if (customerLogin.success)
                    {
                        if (UpdateCustomerAccountProfile(customerLogin.profile.uid, JsonConvert.SerializeObject(customerLogin.profile), customerLogin.session))
                        {
                            return Result<LoginModel>.Make(customerLogin);
                        }
                        //create register existing user of Gtoken master to restaurant.
                        var customer = new CustomerAccount_ToRemove
                        {
                            id = customerLogin.profile.uid,
                            username = customerLogin.profile.account,
                            created_at = DateTime.Now,
                            Profile = customerLogin.profile,
                            session = customerLogin.session
                        };
                        if (CreateCustomerAccount(customer))
                        {
                            return Result<LoginModel>.Make(customerLogin);
                        }
                    }
                }
                return Result<LoginModel>.Null(ErrorCodes.InvalidUserNameOrPassword);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Register new account by calling the Goplay register API
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="pwd"></param>
        /// <param name="game_id"></param>
        /// <param name="email"></param>
        /// <param name="nickname"></param>
        /// <param name="gender"></param>
        /// <param name="referral_code"></param>
        /// <param name="ip_address"></param>
        /// <returns></returns>
        public async Task<Result<LoginModel>> Register(string userName, string pwd, string game_id,
            string email, string nickname, string gender, string referral_code, string ip_address)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = Urls.GetBaseServerUri(); // TODO: Need a switch forlive and debug server //
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/html"));

                // HTTP POST
                var formContent = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("username", userName), 
                    new KeyValuePair<string, string>("password", pwd),
                    new KeyValuePair<string, string>("partner_id", Urls.PARTNER_ID),
                    new KeyValuePair<string, string>("email", email),
                    new KeyValuePair<string, string>("nickname",nickname),
                    new KeyValuePair<string, string>("gender", gender),
                    new KeyValuePair<string, string>("referral_code", referral_code),
                    new KeyValuePair<string, string>("ip_address", ip_address)
                });

                HttpResponseMessage response = await client.PostAsync(Urls.ACTION_REGISTER, formContent);
                if (response.IsSuccessStatusCode)
                {
                    var registerRsult = JsonConvert.DeserializeObject<LoginModel>(await response.Content.ReadAsStringAsync());
                    if (registerRsult.success)
                    {
                        var customer = new CustomerAccount_ToRemove
                        {
                            id = registerRsult.profile.uid,
                            username = registerRsult.profile.account,
                            created_at = DateTime.Now,
                            Profile = registerRsult.profile,
                            session = registerRsult.session
                        };
                        if (CreateCustomerAccount(customer))
                        {
                            return Result<LoginModel>.Make(registerRsult);
                        }
                    }
                    else
                    {
                        // The conversion of Text to Enum should use EnumFromDescription helper //
                        var errCode = EnumConverter.EnumFromDescription<ErrorCodes>(registerRsult.error_code);
                        return Result<LoginModel>.Null(errCode);
                    }
                }
                return Result<LoginModel>.Null(ErrorCodes.NotFound);
            }
        }