| [866] | 1 | using System;
|
|---|
| 2 | using System.Linq;
|
|---|
| 3 | using System.Web.Mvc;
|
|---|
| 4 | using System.Web.Security;
|
|---|
| 5 | using Platnosci.Core.Linq;
|
|---|
| 6 | using Platnosci.Models;
|
|---|
| 7 | using Platnosci.Core.Interface;
|
|---|
| 8 |
|
|---|
| 9 | namespace Platnosci.Controllers
|
|---|
| [932] | 10 | {
|
|---|
| [866] | 11 | [HandleError]
|
|---|
| 12 | public class AccountController : Controller
|
|---|
| 13 | {
|
|---|
| 14 | private readonly IRepository<vPlatnosciEcard> _repository;
|
|---|
| [932] | 15 | private readonly FunkcjePlatnosci _funkcjePlatnosci;
|
|---|
| 16 |
|
|---|
| [866] | 17 | public IFormsAuthentication FormsAuth
|
|---|
| 18 | {
|
|---|
| 19 | get;
|
|---|
| 20 | private set;
|
|---|
| 21 | }
|
|---|
| 22 |
|
|---|
| 23 | public AccountController()
|
|---|
| 24 | {
|
|---|
| [949] | 25 | _repository = new Repository<vPlatnosciEcard>(new DataContext());
|
|---|
| [866] | 26 | FormsAuth = new FormsAuthenticationService();
|
|---|
| [932] | 27 | _funkcjePlatnosci = new FunkcjePlatnosci();
|
|---|
| [866] | 28 | }
|
|---|
| 29 |
|
|---|
| [932] | 30 | public AccountController(IFormsAuthentication formsAuth, IRepository<vPlatnosciEcard> repository, FunkcjePlatnosci func)
|
|---|
| [866] | 31 | {
|
|---|
| 32 | _repository = repository;
|
|---|
| 33 | FormsAuth = formsAuth ?? new FormsAuthenticationService();
|
|---|
| [932] | 34 | _funkcjePlatnosci = func;
|
|---|
| [866] | 35 | }
|
|---|
| 36 |
|
|---|
| 37 | public ActionResult LogOn(string language)
|
|---|
| 38 | {
|
|---|
| [948] | 39 | if (language != "pl" && language != "en" && language != "de")
|
|---|
| 40 | return RedirectToAction("LogOn", "Account", new { language = "pl" });
|
|---|
| 41 |
|
|---|
| [950] | 42 | _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [866] | 43 | return View();
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | [AcceptVerbs(HttpVerbs.Post)]
|
|---|
| 47 | [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1054:UriParametersShouldNotBeStrings",
|
|---|
| 48 | Justification = "Needs to take same parameter type as Controller.Redirect()")]
|
|---|
| [932] | 49 | public ActionResult LogOn(string nip, string numerFaktury, string returnUrl, string language)
|
|---|
| [866] | 50 | {
|
|---|
| [950] | 51 | _funkcjePlatnosci.SetLanguage(language);
|
|---|
| [932] | 52 | var platnosc = new vPlatnosciEcard();
|
|---|
| 53 | if (!ValidateLogOn(nip, numerFaktury))
|
|---|
| [866] | 54 | {
|
|---|
| 55 | return View();
|
|---|
| 56 | }
|
|---|
| [932] | 57 |
|
|---|
| 58 | var login = _repository.FindInvoiceByNipNumber(nip, numerFaktury).SingleOrDefault();
|
|---|
| 59 | platnosc = login;
|
|---|
| 60 | if (platnosc == null) return View();
|
|---|
| 61 | _funkcjePlatnosci.SetUserLogger(nip, numerFaktury);
|
|---|
| [866] | 62 |
|
|---|
| 63 | FormsAuth.SignIn(nip, false);
|
|---|
| [880] | 64 |
|
|---|
| [866] | 65 | if (!String.IsNullOrEmpty(returnUrl))
|
|---|
| 66 | {
|
|---|
| 67 | return Redirect(returnUrl);
|
|---|
| 68 | }
|
|---|
| [932] | 69 |
|
|---|
| 70 | return RedirectToAction("Show", "Platnosc", new { id = platnosc.ID_faktury });
|
|---|
| [866] | 71 | }
|
|---|
| [932] | 72 |
|
|---|
| [866] | 73 | public ActionResult LogOff()
|
|---|
| 74 | {
|
|---|
| 75 | FormsAuth.SignOut();
|
|---|
| 76 | return RedirectToAction("LogOn", "Account");
|
|---|
| 77 | }
|
|---|
| 78 |
|
|---|
| [932] | 79 | private bool ValidateLogOn(string nip, string numerFaktury)
|
|---|
| [866] | 80 | {
|
|---|
| [942] | 81 | var errNip = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_nip").ToString();
|
|---|
| 82 | var errFaktura = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_faktura").ToString();
|
|---|
| 83 | var errTxt = HttpContext.GetGlobalResourceObject("tlumaczenia", "err_logowanie").ToString();
|
|---|
| 84 |
|
|---|
| [866] | 85 | if (String.IsNullOrEmpty(nip))
|
|---|
| [932] | 86 | ModelState.AddModelError("nip", errNip);
|
|---|
| 87 | if (String.IsNullOrEmpty(numerFaktury))
|
|---|
| 88 | ModelState.AddModelError("numerFaktury", errFaktura);
|
|---|
| [942] | 89 |
|
|---|
| [866] | 90 | if (ModelState.IsValid)
|
|---|
| 91 | {
|
|---|
| [932] | 92 | var daneOk = _repository.Exists(u => u.Faktura_Numer == numerFaktury && u.nip == nip);
|
|---|
| 93 | if (daneOk == false)
|
|---|
| [942] | 94 | ModelState.AddModelError("_FORM", errTxt);
|
|---|
| [866] | 95 | }
|
|---|
| 96 | return ModelState.IsValid;
|
|---|
| 97 | }
|
|---|
| 98 | }
|
|---|
| 99 | public interface IFormsAuthentication
|
|---|
| 100 | {
|
|---|
| 101 | void SignIn(string nip, bool createPersistentCookie);
|
|---|
| 102 | void SignOut();
|
|---|
| 103 | }
|
|---|
| 104 |
|
|---|
| 105 | public class FormsAuthenticationService : IFormsAuthentication
|
|---|
| 106 | {
|
|---|
| 107 | public void SignIn(string nip, bool createPersistentCookie)
|
|---|
| 108 | {
|
|---|
| 109 | FormsAuthentication.SetAuthCookie(nip, createPersistentCookie);
|
|---|
| 110 | }
|
|---|
| 111 | public void SignOut()
|
|---|
| 112 | {
|
|---|
| 113 | FormsAuthentication.SignOut();
|
|---|
| 114 | }
|
|---|
| 115 | }
|
|---|
| [932] | 116 | } |
|---|