コード例 #1
0
        public async Task<IdentityResult> RegisterExternal(RegisterExternalModel model)
        {
            var info = await AuthenticationManager.GetExternalLoginInfoAsync();

            if (info == null) return new IdentityResult("External login info not found.");

            var user = new AppUser { UserName = model.UserName, Email = model.Email ?? "" };

            var result = await UserManager.CreateAsync(user);

            if (!result.Succeeded) return result;

            result = await UserManager.AddLoginAsync(user.Id, info.Login);

            if (!result.Succeeded) return result;

            return await UserManager.AddToRoleAsync(user.Id, DefaultUserRole);
        }
コード例 #2
0
 public async Task<IdentityResult> CreateAsync(RegisterModel model)
 {
     var user = new AppUser { UserName = model.UserName, Email = model.Email };
     var result = await UserManager.CreateAsync(user, model.Password);
     if (!result.Succeeded) return result;
     return await UserManager.AddToRoleAsync(user.Id, DefaultUserRole);
 }