Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbannov committed Mar 12, 2024
1 parent addc350 commit e80ed86
Showing 1 changed file with 61 additions and 1 deletion.
62 changes: 61 additions & 1 deletion web/ASC.Web.Api/Api/AuthenticationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public class AuthenticationController(UserManager userManager,
AccountLinker accountLinker,
CoreBaseSettings coreBaseSettings,
StudioNotifyService studioNotifyService,
UserManagerWrapper userManagerWrapper,
UserHelpTourHelper userHelpTourHelper,
Signature signature,
DisplayUserSettingsHelper displayUserSettingsHelper,
Expand Down Expand Up @@ -544,7 +545,6 @@ private async Task<UserInfo> GetUserByThirdParty(LoginProfile loginProfile)

await studioNotifyService.UserHasJoinAsync();
await userHelpTourHelper.SetIsNewUser(true);
//await personalSettingsHelper.SetIsNewUser(true);
}

return userInfo;
Expand All @@ -558,6 +558,66 @@ private async Task<UserInfo> GetUserByThirdParty(LoginProfile loginProfile)
}
}

private async Task<UserInfo> JoinByThirdPartyAccount(LoginProfile loginProfile)
{
if (string.IsNullOrEmpty(loginProfile.EMail))
{
throw new Exception(Resource.ErrorNotCorrectEmail);
}

var userInfo = await userManager.GetUserByEmailAsync(loginProfile.EMail);
if (!await userManager.UserExistsAsync(userInfo.Id))
{
var newUserInfo = ProfileToUserInfo(loginProfile);

try
{
await securityContext.AuthenticateMeWithoutCookieAsync(ASC.Core.Configuration.Constants.CoreSystem);
userInfo = await userManagerWrapper.AddUserAsync(newUserInfo, UserManagerWrapper.GeneratePassword());
}
finally
{
securityContext.Logout();
}
}

await accountLinker.AddLinkAsync(userInfo.Id, loginProfile);

return userInfo;
}

private UserInfo ProfileToUserInfo(LoginProfile loginProfile)
{
if (string.IsNullOrEmpty(loginProfile.EMail))
{
throw new Exception(Resource.ErrorNotCorrectEmail);
}

var firstName = loginProfile.FirstName;
if (string.IsNullOrEmpty(firstName))
{
firstName = loginProfile.DisplayName;
}

var userInfo = new UserInfo
{
FirstName = string.IsNullOrEmpty(firstName) ? UserControlsCommonResource.UnknownFirstName : firstName,
LastName = string.IsNullOrEmpty(loginProfile.LastName) ? UserControlsCommonResource.UnknownLastName : loginProfile.LastName,
Email = loginProfile.EMail,
Title = string.Empty,
Location = string.Empty,
CultureName = coreBaseSettings.CustomMode ? "ru-RU" : Thread.CurrentThread.CurrentUICulture.Name,
ActivationStatus = EmployeeActivationStatus.Activated
};

var gender = loginProfile.Gender;
if (!string.IsNullOrEmpty(gender))
{
userInfo.Sex = gender == "male";
}

return userInfo;
}
private async Task<(bool, Guid)> TryGetUserByHashAsync(string hashId)
{
var userId = Guid.Empty;
Expand Down

0 comments on commit e80ed86

Please sign in to comment.