diff options
| author | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-11 03:37:33 +0300 |
|---|---|---|
| committer | Roy Ben Shabat <Roy.mail.net@gmail.com> | 2020-05-11 03:37:33 +0300 |
| commit | d4adb3a3faa36b4500c17e661e09ec2af338b353 (patch) | |
| tree | e31967e0e9b9dd198c8bf646c1c3c22599badada /Software/Visual_Studio/Web | |
| parent | 9ead141002c63c1a44d7851fa4a4a1902c0bfe89 (diff) | |
| download | Tango-d4adb3a3faa36b4500c17e661e09ec2af338b353.tar.gz Tango-d4adb3a3faa36b4500c17e661e09ec2af338b353.zip | |
User invitation via Email !
Diffstat (limited to 'Software/Visual_Studio/Web')
4 files changed, 71 insertions, 18 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs index 7bf420df9..01878f16a 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs @@ -1,10 +1,13 @@ -using System; +using SendGrid; +using SendGrid.Helpers.Mail; +using System; using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Http; using System.Security.Authentication; using System.Threading.Tasks; +using System.Web; using System.Web.Http; using Tango.BL; using Tango.BL.Builders; @@ -78,22 +81,6 @@ namespace Tango.MachineService.Controllers AccessTokenExpiration = accessToken.ExpiresOn.UtcDateTime }; - - //Enforce Machine Studio Version ? - //if (MachineServiceConfig.ENFORCE_MACHINE_STUDIO_VERSION) - //{ - // using (var db = ObservablesContextHelper.CreateContext()) - // { - // var latest_version = db.MachineStudioVersions.ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault(); - - // if (latest_version != null && Version.Parse(latest_version.Version) != client_version) - // { - // versionChangeRequired = true; - // requiredVersion = latest_version.Version; - // } - // } - //} - //Return data source return new LoginResponse() { @@ -230,5 +217,64 @@ namespace Tango.MachineService.Controllers Expiration = accessToken.ExpiresOn.UtcDateTime, }; } + + [HttpPost] + [JwtTokenFilter] + public UserInvitationEmailResponse SendUserInvitationEmail(UserInvitationEmailRequest request) + { + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + if (!db.Users.Any(x => x.Email.ToLower() == request.Email.ToLower())) + { + throw new InvalidOperationException("User not found."); + } + } + + var client = new SendGridClient(MachineServiceConfig.SEND_GRID_API_KEY); + SendGridMessage msg = new SendGridMessage(); + msg.SetFrom("info@twine-s.com", "Twine Solutions LTD"); + msg.AddTo(request.Email); + msg.Subject = "Welcome To Tango FSE"; + msg.SetTemplateId("d-2af42ed0ea3c44b3abaa61016223555a"); + + var dynamicTemplateData = new + { + DownloadUrl = $"{request.MachineServiceAddress}/fse", + request.FullName, + request.Password, + }; + + msg.SetTemplateData(dynamicTemplateData); + + var result = client.SendEmailAsync(msg).GetAwaiter().GetResult(); + + if (result.StatusCode != HttpStatusCode.Accepted) + { + throw new HttpException(result.StatusCode.ToString()); + } + + return new UserInvitationEmailResponse(); + } + + [HttpPost] + public ForgotPasswordResponse SendForgotPasswordEmail(ForgotPasswordRequest request) + { + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + if (!db.Users.Any(x => x.Email.ToLower() == request.Email.ToLower())) + { + throw new InvalidOperationException("User not found."); + } + } + + //TODO: create a special link that when surfed will reset the password for the user and display the new temp password. + return new ForgotPasswordResponse(); + } + + [HttpGet] + public String ResetPassword(String guid) + { + return String.Empty; //Reset the password and return the new temp password. + } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs index 2a844fbc3..bdddbab8f 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/MachineServiceConfig.cs @@ -23,5 +23,7 @@ namespace Tango.MachineService public static String TFS_PERSONAL_TOKEN => ConfigurationManager.AppSettings[nameof(TFS_PERSONAL_TOKEN)].ToString(); public static String FSE_TFS_USER_EMAIL => ConfigurationManager.AppSettings[nameof(FSE_TFS_USER_EMAIL)].ToString(); + + public static String SEND_GRID_API_KEY => ConfigurationManager.AppSettings[nameof(SEND_GRID_API_KEY)].ToString(); } }
\ No newline at end of file diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj index 67617ec7f..ea70fb7a6 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj +++ b/Software/Visual_Studio/Web/Tango.MachineService/Tango.MachineService.csproj @@ -188,6 +188,9 @@ <Reference Include="Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5, processorArchitecture=MSIL"> <HintPath>..\..\packages\Owin.1.0\lib\net40\Owin.dll</HintPath> </Reference> + <Reference Include="SendGrid"> + <HintPath>..\..\Referenced Assemblies\SendGrid\SendGrid.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Data.DataSetExtensions" /> @@ -480,7 +483,7 @@ <SaveServerSettingsInUserFile>False</SaveServerSettingsInUserFile> </WebProjectProperties> </FlavorProperties> - <UserProperties BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UseGlobalSettings="False" BuildVersion_StartDate="2000/1/1" /> + <UserProperties BuildVersion_StartDate="2000/1/1" BuildVersion_UseGlobalSettings="False" BuildVersion_BuildVersioningStyle="None.None.Increment.TimeStamp" BuildVersion_UpdateAssemblyVersion="True" BuildVersion_AssemblyInfoFilename="Properties\AssemblyInfo.cs" /> </VisualStudio> </ProjectExtensions> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Web.config b/Software/Visual_Studio/Web/Tango.MachineService/Web.config index e90953ea2..9cfdc9ccd 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Web.config +++ b/Software/Visual_Studio/Web/Tango.MachineService/Web.config @@ -36,6 +36,8 @@ <add key="TFS_COLLECTION_URL" value="https://twinetfs.visualstudio.com" /> <add key="TFS_PERSONAL_TOKEN" value="pyulwgs7m3v7pizz3oxusypdkdfw43txggo5mjwu2ouyv2qwprhq" /> <add key="FSE_TFS_USER_EMAIL" value="fse@twine-s.com" /> + + <add key="SEND_GRID_API_KEY" value="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" /> </appSettings> <!-- For a description of web.config changes see http://go.microsoft.com/fwlink/?LinkId=235367. |
