public async Task <IActionResult> OnPostAsync([FromBody] RegisterVM registerVM)
        {
            MemberRepo cRP = new MemberRepo(_context);

            ExternalLogins = (await _signInManager.GetExternalAuthenticationSchemesAsync()).ToList();
            if (ModelState.IsValid)
            {
                if (cRP.checkExist(registerVM.Email))
                {
                    var Obj = new
                    {
                        errorMessage = "User Already Exist",
                        StatusCode   = "Invalid Register."
                    };

                    return(new ObjectResult(Obj));
                }
                var user = new IdentityUser {
                    UserName = registerVM.Email, Email = registerVM.Email,
                };
                var result = await _userManager.CreateAsync(user, registerVM.Password);

                if (result.Succeeded)
                {
                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));
                    var enCode = Encoding.UTF8.GetString(WebEncoders.Base64UrlDecode(code));
                    await _userManager.ConfirmEmailAsync(user, enCode);

                    bool isNewClient = cRP.Create(registerVM.Username, registerVM.LastName, registerVM.FirstName, registerVM.Email);

                    if (isNewClient)
                    {
                        var tokenString = GenerateJSONWebToken(user);
                        var jsonOK      = new
                        {
                            tokenString = tokenString,
                            StatusCode  = "OK",
                            currentUser = registerVM.Email
                        };

                        return(new ObjectResult(jsonOK));
                    }
                }
            }
            var jsonInvalid = new { tokenString = "", StatusCode = "Invalid register." };

            return(new ObjectResult(jsonInvalid));
        }
Esempio n. 2
0
        public bool CreateMember(MemberViewModel member)
        {
            try
            {
                mrp.Create(new Member
                {
                    Username     = member.Username,
                    Password     = member.Password,
                    MemberTypeId = 3
                });

                return(true);
            }
            catch (Exception e)
            {
                return(false);
            }
        }