public async Task <bool> isMailExisting(string email, IStObjMap stObjMap) { try { SqlDefaultDatabase db = stObjMap.StObjs.Obtain <SqlDefaultDatabase>(); using (var ctx = new SqlStandardCallContext()) { UserQueries groupQueries = new UserQueries(ctx, db); int exists = await groupQueries.CheckEmail(email); if (exists != 0) { return(true); } else { return(false); } } } catch { return(false); } }
public async Task <int> CheckIfUserExists(IStObjMap stObjMap, IAuthenticationInfo authenticationInfo, string mail, string userName, string firstName, string lastName) { using (var ctx = new SqlStandardCallContext()) { var sqlDatabase = stObjMap.StObjs.Obtain <SqlDefaultDatabase>(); var userTable = stObjMap.StObjs.Obtain <CustomUserTable>(); var actorEmail = stObjMap.StObjs.Obtain <ActorEMailTable>(); var basic = stObjMap.StObjs.Obtain <IBasicAuthenticationProvider>(); UserQueries userQueries = new UserQueries(ctx, sqlDatabase); int currentIdUser = authenticationInfo.ActualUser.UserId; int idUser = await userQueries.CheckEmail(mail); if (idUser != 0) { return(idUser); } else { string tempPwd = RandomPassword(); string subject = "Vous êtes invité à rejoindre la plateforme InProject"; string mailContent = "Afin de vous connectez a la plateforme InProject voici votre mot de passe provisoire: " + tempPwd + " il est conseillé de modifier ce mot de passe lors de votre première connection"; int newUserId = await userTable.CreateUserAsync(ctx, currentIdUser, userName, firstName, lastName); await actorEmail.AddEMailAsync(ctx, 1, newUserId, mail, true, false); await basic.CreateOrUpdatePasswordUserAsync(ctx, 1, newUserId, tempPwd); //await _emailSender.SendMessage( mail, subject, mailContent ); return(newUserId); } } }
public async Task <UserLoginResult> CreateAccountAndLoginAsync(IActivityMonitor monitor, IWebFrontAuthAutoCreateAccountContext context) { var userTable = _stObjMap.StObjs.Obtain <CustomUserTable>(); var actorEmail = _stObjMap.StObjs.Obtain <ActorEMailTable>(); var oidcTable = _stObjMap.StObjs.Obtain <UserOidcTable>(); ICustomUserOidcInfos infos = (ICustomUserOidcInfos)context.Payload; ISqlCallContext ctx = context.HttpContext.RequestServices.GetService <ISqlCallContext>(); SqlDefaultDatabase db = _stObjMap.StObjs.Obtain <SqlDefaultDatabase>(); using (var sqlCtx = new SqlStandardCallContext()) { UserQueries userQueries = new UserQueries(sqlCtx, db); int exists = await userQueries.CheckEmail(infos.Email); if (exists == 0) { int userId = await userTable.CreateUserAsync(ctx, 1, Guid.NewGuid().ToString(), infos.FirstName, infos.LastName); await actorEmail.AddEMailAsync(ctx, 1, userId, infos.Email, true, false); UCLResult result = await oidcTable.CreateOrUpdateOidcUserAsync( ctx, 1, userId, infos, UCLMode.CreateOrUpdate | UCLMode.WithActualLogin); if (result.OperationResult != UCResult.Created) { return(null); } return(await _dbAuth.CreateUserLoginResultFromDatabase(ctx, _typeSystem, result.LoginResult)); } else { UCLResult result = await oidcTable.CreateOrUpdateOidcUserAsync( ctx, 1, exists, infos, UCLMode.CreateOrUpdate | UCLMode.WithActualLogin); return(await _dbAuth.CreateUserLoginResultFromDatabase(ctx, _typeSystem, result.LoginResult)); } } }