コード例 #1
0
        public async Task <IActionResult> Signup(string email, string password)
        {
            IAuthUser user = new AuthUser()
            {
                Email    = email,
                Password = password,
                Role     = "member"
            };

            user.HashPassword(); //do this before saving to DB

            try
            {
                user = await Auth.CreateAccount(user);
            }
            catch (CreateAccountException ex)
            {
                return(Json(new
                {
                    success = false,
                    error = ex.Message
                }));
            }
            catch (Exception ex)
            {
                return(Json(new
                {
                    success = false,
                    error = "An unknown error occurred. Please try again later."
                }));
            }

            Response.CreateAuthCookie(user.ID, "DBID");

            return(Json(new
            {
                success = true,
                redirect = "/dashboard"
            }));
        }