コード例 #1
0
        public async Task<JsonResult> Register(RegisterViewModel model)
        {
            try
            {
                if (!ModelState.IsValid
                    || String.IsNullOrEmpty(model.submit) || model.submit != "submit")
                {
                    //Something failed, display errors
                    return Json(new { errors = Errors(ModelState) });
                }

                var api = Platform.Core.Api.Instance;
                string ip = Request.UserHostAddress == null || Request.UserHostAddress == "::1"
                    ? IPAdressExtension.GetDefaultIp()
                    : Request.UserHostAddress;

                var result = api.Register(model.username.ToLower(),
                    model.password,
                    null,
                    model.username.ToLower(),
                    model.email.ToLower(),
                    Genders.Male,
                    model.referralID,
                    ip,
                    model.countryCode,
                    model.countryName);
                api.UpdateCustomerAccount(result.Data.id, result.Data.country_code, result.Data.country_name, DateTime.UtcNow);

                //Login User
                var applicationUser = new ApplicationUser()
                {
                    Id = result.Data.id,
                    Email = result.Data.email,
                    UserName = result.Data.username
                };

                await SignInAsync(applicationUser, false);

                return Json(new { success = true, redirect = Url.Action("index", "transaction") });
            }
            catch
            {
                ModelState.AddModelError("CustomError", Messages.MISSING_FIELDS);
                return Json(new { errors = Errors(ModelState) });
            }
        }
コード例 #2
0
        public ActionResult Register(string referralID = null)
        {
            var api = Platform.Core.Api.Instance;
            if (!api.IsUserExist(referralID))
            {
                referralID = string.Empty;
            }
            var countryCode = string.Empty;
            var countryName = string.Empty;

            IPAddress ip = GToken.Web.Helpers.Extensions.IpHelper.GetClientIp(Request);
            if (ip.Equals(IPAddress.Parse("127.0.0.1")))
            {
                countryCode = "SG";
                countryName = "Singapore";
            }
            else
            {
                ip.GetCountryCode(c => countryCode = c, n => countryName = n);
            }
            var model = new RegisterViewModel
            {
                referralID = referralID,
                countryCode = countryCode,
                countryName = countryName
            };
            return View(model);
        }