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