Podpiecie do mailSendera

This commit is contained in:
Bartosz Chyzy 2018-12-19 13:50:49 +01:00
parent 851b633e31
commit 3fd3fc128c
6 changed files with 31 additions and 5 deletions

View File

@ -136,7 +136,7 @@ namespace Forum.Controllers
// //
// GET: /Account/Register // GET: /Account/Register
[Authorize] [AllowAnonymous]
public ActionResult Register() public ActionResult Register()
{ {
return View(); return View();
@ -145,7 +145,7 @@ namespace Forum.Controllers
// //
// POST: /Account/Register // POST: /Account/Register
[HttpPost] [HttpPost]
[Authorize] [AllowAnonymous]
[ValidateAntiForgeryToken] [ValidateAntiForgeryToken]
public async Task<ActionResult> Register(RegisterViewModel model) public async Task<ActionResult> Register(RegisterViewModel model)
{ {

View File

@ -1,8 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.Entity; using System.Data.Entity;
using System.Linq; using System.Linq;
using System.Security.Principal;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Web.Mvc; using System.Web.Mvc;
using Fluentx.Mvc;
using Forum.DataAccessLayer; using Forum.DataAccessLayer;
using Forum.DataAccessLayer.Models; using Forum.DataAccessLayer.Models;
using Forum.ViewModels; using Forum.ViewModels;
@ -113,6 +117,19 @@ namespace Forum.Controllers
question.Answers.Add(answer); question.Answers.Add(answer);
_dbContext.SaveChanges(); _dbContext.SaveChanges();
//Logika wysylania maili
if (User.Identity.IsAuthenticated && !string.IsNullOrEmpty(question.ReportersEmail))
{
var dataToPost = new Dictionary<string, object>();
dataToPost.Add("Subject",question.Title);
dataToPost.Add("EMailTo",question.ReportersEmail);
dataToPost.Add("Content",model.Content);
return this.RedirectAndPost(ConfigurationManager.AppSettings["MailSenderAddress"], dataToPost);
}
return RedirectToAction("Question", new {id = model.QuestionId}); return RedirectToAction("Question", new {id = model.QuestionId});
} }

View File

@ -47,6 +47,12 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="Fluentx, Version=2.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Fluentx.2.0.4\lib\Fluentx.dll</HintPath>
</Reference>
<Reference Include="Fluentx.Mvc, Version=1.0.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Fluentx.Mvc.1.0.4\lib\Fluentx.Mvc.dll</HintPath>
</Reference>
<Reference Include="Microsoft.AspNet.TelemetryCorrelation, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.AspNet.TelemetryCorrelation, Version=1.0.4.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.4\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll</HintPath> <HintPath>..\packages\Microsoft.AspNet.TelemetryCorrelation.1.0.4\lib\net45\Microsoft.AspNet.TelemetryCorrelation.dll</HintPath>
</Reference> </Reference>

View File

@ -12,6 +12,7 @@
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\ForumInzyneria1.mdf;Initial Catalog=ForumInzyneria1;Integrated Security=True" providerName="System.Data.SqlClient" /> <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\ForumInzyneria1.mdf;Initial Catalog=ForumInzyneria1;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings> </connectionStrings>
<appSettings> <appSettings>
<add key="MailSenderAddress" value="http://localhost:51829/Home/Index" />
<add key="webpages:Version" value="3.0.0.0" /> <add key="webpages:Version" value="3.0.0.0" />
<add key="webpages:Enabled" value="false" /> <add key="webpages:Enabled" value="false" />
<add key="ClientValidationEnabled" value="true" /> <add key="ClientValidationEnabled" value="true" />
@ -86,7 +87,7 @@
</dependentAssembly> </dependentAssembly>
<dependentAssembly> <dependentAssembly>
<assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /> <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
<bindingRedirect oldVersion="1.0.0.0-5.2.7.0" newVersion="5.2.7.0" /> <bindingRedirect oldVersion="0.0.0.0-5.2.7.0" newVersion="5.2.7.0" />
</dependentAssembly> </dependentAssembly>
</assemblyBinding> </assemblyBinding>
</runtime> </runtime>

View File

@ -3,6 +3,8 @@
<package id="Antlr" version="3.5.0.2" targetFramework="net461" /> <package id="Antlr" version="3.5.0.2" targetFramework="net461" />
<package id="bootstrap" version="3.3.7" targetFramework="net461" /> <package id="bootstrap" version="3.3.7" targetFramework="net461" />
<package id="EntityFramework" version="6.2.0" targetFramework="net461" /> <package id="EntityFramework" version="6.2.0" targetFramework="net461" />
<package id="Fluentx" version="2.0.4" targetFramework="net461" />
<package id="Fluentx.Mvc" version="1.0.4" targetFramework="net461" />
<package id="jQuery" version="3.3.1" targetFramework="net461" /> <package id="jQuery" version="3.3.1" targetFramework="net461" />
<package id="jQuery.Validation" version="1.17.0" targetFramework="net461" /> <package id="jQuery.Validation" version="1.17.0" targetFramework="net461" />
<package id="Microsoft.AspNet.Identity.Core" version="2.2.2" targetFramework="net461" /> <package id="Microsoft.AspNet.Identity.Core" version="2.2.2" targetFramework="net461" />

View File

@ -13,8 +13,8 @@ namespace MailSender.Controllers
[HttpGet] [HttpGet]
public ActionResult Index() public ActionResult Index()
{ {
var model = JsonConvert.SerializeObject(new Models.MailModel() { Content = "DDD", EMailTo = "ddd@o2.pl", Subject = "LLLLLL" }); //var model = JsonConvert.SerializeObject(new Models.MailModel() { Content = "DDD", EMailTo = "ddd@o2.pl", Subject = "LLLLLL" });
TempData.Add("mailModel", model); //TempData.Add("mailModel", model);
return RedirectToAction("Index", "Home"); return RedirectToAction("Index", "Home");
} }
} }