コード例 #1
0
        public async Task <ActionResult <JwtTokenModel> > Register([FromBody] RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var gravatarUrl = GravatarHelper.GetAvatarUrl(model.Email);
                var user        = new ApplicationUser
                {
                    UserName  = model.Name,
                    Email     = model.Email,
                    AvatarUrl = gravatarUrl
                };

                var result = await _userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await _signInManager.SignInAsync(user, false);

                    var jwtToken = await _tokenService.GetJwtToken(user);

                    return(jwtToken);
                }
                var errors = AuthHelper.GetErrors(result);
                return(BadRequest(errors));
            }

            return(BadRequest(ModelState));
        }
コード例 #2
0
        public void GetAvatarUrl_ManyEmailFormats_Url()
        {
            var expected = GravatarHelper.GetAvatarUrl("*****@*****.**");

            Assert.AreEqual("http://www.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg", expected);

            expected = GravatarHelper.GetAvatarUrl("*****@*****.**");
            Assert.AreEqual("http://www.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg", expected);

            expected = GravatarHelper.GetAvatarUrl(" [email protected] ");
            Assert.AreEqual("http://www.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg", expected);
        }
コード例 #3
0
        public void GetAvatarUrl_EmailAndAllOptions_Url()
        {
            var expected = GravatarHelper.GetAvatarUrl("*****@*****.**", 64, "mm", true, "x", true);

            Assert.AreEqual("http://secure.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg?s=64&d=mm&f=y&r=x", expected);
        }
コード例 #4
0
        public void GetAvatarUrl_EmailAndSecureRequest_Url()
        {
            var expected = GravatarHelper.GetAvatarUrl("*****@*****.**", secureRequest: true);

            Assert.AreEqual("http://secure.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg", expected);
        }
コード例 #5
0
        public void GetAvatarUrl_EmailAndRating_Url()
        {
            var expected = GravatarHelper.GetAvatarUrl("*****@*****.**", rating: "pg");

            Assert.AreEqual("http://www.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg?r=pg", expected);
        }
コード例 #6
0
        public void GetAvatarUrl_EmailAndForceDefaultImage_Url()
        {
            var expected = GravatarHelper.GetAvatarUrl("*****@*****.**", forceDefaultImage: true);

            Assert.AreEqual("http://www.gravatar.com/avatar/c5c70a93a2b605756df1af5da0dd413f.jpg?f=y", expected);
        }
コード例 #7
0
 public void GetAvatarUrl_NullOrEmpty_Exception()
 {
     GravatarHelper.GetAvatarUrl(null);
 }