/// <summary> /// Sign in a user that has already been authenticated. /// </summary> public async Task SignMemberInAsync(SignMemberInCommand command) { // Because we're not logged in yet we need to elevate permissions here to save a new user, // otherwise the ambient anonymous user will be used and a permission exception will be thrown var systemExecutionContext = await _executionContextFactory.CreateSystemUserExecutionContextAsync(); var existingUser = await _userRepository.GetUserMicroSummaryByEmailAsync(command.Email, MemberUserArea.AreaCode, systemExecutionContext); int userId; if (existingUser == null) { // If we haven't logged in with this user before, we'll create a Cofoundry user to match your // SSO login. var role = await GetMemberRole(systemExecutionContext); var addUserCommand = MapAddUserCommand(command, role); await _userRepository.AddUserAsync(addUserCommand, systemExecutionContext); // Note that the new user id is set in the OutputUserId which is a // convention used by the CQS framework (see https://github.com/cofoundry-cms/cofoundry/wiki/CQS) userId = addUserCommand.OutputUserId; } else { // If the user already exists, we sign in using that Id userId = existingUser.UserId; } await _loginService.LogAuthenticatedUserInAsync(MemberUserArea.AreaCode, userId, true); }
/// <summary> /// We're going to make use of the built in AddUserCommand which will take /// care of most of the user creation logic for us. Here we map from our /// domain command to the Cofoundry one. /// </summary> private AddUserCommand MapAddUserCommand(SignMemberInCommand command, RoleDetails role) { var addUserCommand = new AddUserCommand(); addUserCommand.Email = command.Email; addUserCommand.FirstName = "Unknown"; addUserCommand.LastName = "Unknown"; addUserCommand.RoleId = role.RoleId; addUserCommand.UserAreaCode = MemberUserArea.AreaCode; return(addUserCommand); }
public async Task <ActionResult> SignIn(SignMemberInCommand command) { if (_memberLoginService.IsAuthenticated(command)) { await _memberLoginService.SignMemberInAsync(command); return(Redirect("/")); } var vm = await GetSignInViewModel(); return(View(vm)); }
public bool IsAuthenticated(SignMemberInCommand command) { // TODO: Add in your own auth integration here return(true); }