Ejemplo n.º 1
0
        public Claim[] OnVerify(Claim[] claims, JObject payload, string identifier, out bool valid)
        {
            valid = false;
            var user = _applicationUserManager.FindByNameAsync(payload["phone"].ToString()).Result;

            if (user == null)
            {
                user = new User {
                    UserName       = payload["phone"].ToString(),
                    IsActive       = true,
                    EmailConfirmed = true
                };

                var result = _applicationUserManager.CreateUserAsync(user).Result;

                if (!result.Succeeded)
                {
                    Exception ex = new Exception();

                    ex.Data.Add(Gp_Error.IdentityResultFaild, result.Errors.ToList());
                    throw ex;
                }
            }

            valid = true;
            return(new Claim[]
            {
                new Claim(identifier, user.Id.ToString()),
                new Claim("phone", user.PhoneNumber),
            });
        }
Ejemplo n.º 2
0
        public async Task <IdentityResult> Register()
        {
            var user = new User {
                UserName  = _user.Phone,
                FirstName = _user.FirstName,
                LastName  = _user.LastName,
                Email     = _user.Email,
                IsActive  = true
            };
            var result = await _applicationUserManager.CreateUserAsync(user);

            return(result);
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Register(IndexViewModel model)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var user = new ApplicationUser
                    {
                        DisplayName = model.Register.DisplayName,
                        Email       = model.Register.Email,
                        UserName    = model.Register.Email,
                        CurrentExp  = 100, // set user exp default by 100
                    };
                    // Create user
                    var result = await m_userManager.CreateUserAsync(user, model.Register.Password);

                    // Check if successfull
                    if (result == IdentityResult.Success)
                    {
                        // Login into system
                        await SignInAsync(user, false);

                        //Add registed Successfully exp reward for user
                        await m_expService.AddExpForRegisterAsync(user.Id);

                        //Init currency amount
                        await m_currencyUserService.CreateAsync(EntityFactory.CreateCurrency_UserObject(user.Id, Constraint.CurrencySystem.DIAMOND));

                        await m_currencyUserService.CreateAsync(EntityFactory.CreateCurrency_UserObject(user.Id, Constraint.CurrencySystem.STARFISH));

                        await m_currencyUserService.CreateAsync(EntityFactory.CreateCurrency_UserObject(user.Id, Constraint.CurrencySystem.HEART));

                        // redirect to galaxy-gate
                        return(RedirectToAction("Index", "Home", new { area = "galaxygate" }));
                    }
                    else // If failure
                    {////[RequireHttps]
                        TempData["RegisterMessage"] = result.Errors.First();
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                catch (Exception ex)
                {
                    ViewBag.ErrorMessage = ex.Message;
                    ViewBag.Exception    = ex.ToString();
                    return(View("Error"));
                }
            }
            // If we got this far, something failed, redisplay form
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> PostAsync([FromBody] CreateUserModel createUserModel)
        {
            try
            {
                if (createUserModel.Id == Guid.Empty)
                {
                    var userModel = _mapper.Map <UserModel>(createUserModel);

                    var result = await _applicationUserManager.CreateUserAsync(userModel, ModelState, createUserModel.Password, createUserModel.PasswordConfirm, Guid.Parse(_userProvider.GetTenantId()));

                    if (result.Succeeded)
                    {
                        return(Created(new Uri($"{Request.Path}/{userModel.Id}", UriKind.Absolute), userModel));
                    }
                }
            }
            catch (Exception e)
            {
                string message = e.Message;
            }

            return(BadRequest());
        }