1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Web;
|
---|
5 | using System.Web.Mvc;
|
---|
6 | using System.Web.Routing;
|
---|
7 | using System.Web.Security;
|
---|
8 | using HeuristicLab.Services.Optimization.Web.Models;
|
---|
9 | using System.ServiceModel;
|
---|
10 | using HeuristicLab.Services.Optimization.ControllerService;
|
---|
11 | using System.ServiceModel.Description;
|
---|
12 |
|
---|
13 | namespace HeuristicLab.Services.Optimization.Web.Controllers {
|
---|
14 | public class AccountController : Controller {
|
---|
15 |
|
---|
16 | //
|
---|
17 | // GET: /Account/LogOn
|
---|
18 |
|
---|
19 | public ActionResult LogOn() {
|
---|
20 | return View();
|
---|
21 | }
|
---|
22 |
|
---|
23 | //
|
---|
24 | // POST: /Account/LogOn
|
---|
25 |
|
---|
26 | [HttpPost]
|
---|
27 | public ActionResult LogOn(LogOnModel model, string returnUrl) {
|
---|
28 | if (ModelState.IsValid) {
|
---|
29 | if (Membership.ValidateUser(model.UserName, model.Password)) {
|
---|
30 | FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
|
---|
31 | Session["pw"] = model.Password;
|
---|
32 | if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/")
|
---|
33 | && !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\")) {
|
---|
34 | return Redirect(returnUrl);
|
---|
35 | }
|
---|
36 | else {
|
---|
37 | return RedirectToAction("Index", "Home");
|
---|
38 | }
|
---|
39 | }
|
---|
40 | else {
|
---|
41 | ModelState.AddModelError("", "The user name or password provided is incorrect.");
|
---|
42 | }
|
---|
43 | }
|
---|
44 |
|
---|
45 | // If we got this far, something failed, redisplay form
|
---|
46 | return View(model);
|
---|
47 | }
|
---|
48 |
|
---|
49 | //
|
---|
50 | // GET: /Account/LogOff
|
---|
51 |
|
---|
52 | public ActionResult LogOff() {
|
---|
53 | FormsAuthentication.SignOut();
|
---|
54 |
|
---|
55 | return RedirectToAction("Index", "Home");
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | ////
|
---|
60 | //// GET: /Account/Register
|
---|
61 |
|
---|
62 | //public ActionResult Register() {
|
---|
63 | // return View();
|
---|
64 | //}
|
---|
65 |
|
---|
66 | ////
|
---|
67 | //// POST: /Account/Register
|
---|
68 |
|
---|
69 | //[HttpPost]
|
---|
70 | //public ActionResult Register(RegisterModel model) {
|
---|
71 | // if (ModelState.IsValid) {
|
---|
72 | // // Attempt to register the user
|
---|
73 | // MembershipCreateStatus createStatus;
|
---|
74 | // Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
|
---|
75 |
|
---|
76 | // if (createStatus == MembershipCreateStatus.Success) {
|
---|
77 | // FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
|
---|
78 | // return RedirectToAction("Index", "Home");
|
---|
79 | // }
|
---|
80 | // else {
|
---|
81 | // ModelState.AddModelError("", ErrorCodeToString(createStatus));
|
---|
82 | // }
|
---|
83 | // }
|
---|
84 |
|
---|
85 | // // If we got this far, something failed, redisplay form
|
---|
86 | // return View(model);
|
---|
87 | //}
|
---|
88 |
|
---|
89 | ////
|
---|
90 | //// GET: /Account/ChangePassword
|
---|
91 |
|
---|
92 | //[Authorize]
|
---|
93 | //public ActionResult ChangePassword() {
|
---|
94 | // return View();
|
---|
95 | //}
|
---|
96 |
|
---|
97 | ////
|
---|
98 | //// POST: /Account/ChangePassword
|
---|
99 |
|
---|
100 | //[Authorize]
|
---|
101 | //[HttpPost]
|
---|
102 | //public ActionResult ChangePassword(ChangePasswordModel model) {
|
---|
103 | // if (ModelState.IsValid) {
|
---|
104 |
|
---|
105 | // // ChangePassword will throw an exception rather
|
---|
106 | // // than return false in certain failure scenarios.
|
---|
107 | // bool changePasswordSucceeded;
|
---|
108 | // try {
|
---|
109 | // MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
|
---|
110 | // changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
|
---|
111 | // }
|
---|
112 | // catch (Exception) {
|
---|
113 | // changePasswordSucceeded = false;
|
---|
114 | // }
|
---|
115 |
|
---|
116 | // if (changePasswordSucceeded) {
|
---|
117 | // return RedirectToAction("ChangePasswordSuccess");
|
---|
118 | // }
|
---|
119 | // else {
|
---|
120 | // ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
|
---|
121 | // }
|
---|
122 | // }
|
---|
123 |
|
---|
124 | // // If we got this far, something failed, redisplay form
|
---|
125 | // return View(model);
|
---|
126 | //}
|
---|
127 |
|
---|
128 | ////
|
---|
129 | //// GET: /Account/ChangePasswordSuccess
|
---|
130 |
|
---|
131 | //public ActionResult ChangePasswordSuccess() {
|
---|
132 | // return View();
|
---|
133 | //}
|
---|
134 |
|
---|
135 | #region Status Codes
|
---|
136 | private static string ErrorCodeToString(MembershipCreateStatus createStatus) {
|
---|
137 | // See http://go.microsoft.com/fwlink/?LinkID=177550 for
|
---|
138 | // a full list of status codes.
|
---|
139 | switch (createStatus) {
|
---|
140 | case MembershipCreateStatus.DuplicateUserName:
|
---|
141 | return "User name already exists. Please enter a different user name.";
|
---|
142 |
|
---|
143 | case MembershipCreateStatus.DuplicateEmail:
|
---|
144 | return "A user name for that e-mail address already exists. Please enter a different e-mail address.";
|
---|
145 |
|
---|
146 | case MembershipCreateStatus.InvalidPassword:
|
---|
147 | return "The password provided is invalid. Please enter a valid password value.";
|
---|
148 |
|
---|
149 | case MembershipCreateStatus.InvalidEmail:
|
---|
150 | return "The e-mail address provided is invalid. Please check the value and try again.";
|
---|
151 |
|
---|
152 | case MembershipCreateStatus.InvalidAnswer:
|
---|
153 | return "The password retrieval answer provided is invalid. Please check the value and try again.";
|
---|
154 |
|
---|
155 | case MembershipCreateStatus.InvalidQuestion:
|
---|
156 | return "The password retrieval question provided is invalid. Please check the value and try again.";
|
---|
157 |
|
---|
158 | case MembershipCreateStatus.InvalidUserName:
|
---|
159 | return "The user name provided is invalid. Please check the value and try again.";
|
---|
160 |
|
---|
161 | case MembershipCreateStatus.ProviderError:
|
---|
162 | return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
|
---|
163 |
|
---|
164 | case MembershipCreateStatus.UserRejected:
|
---|
165 | return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
|
---|
166 |
|
---|
167 | default:
|
---|
168 | return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
|
---|
169 | }
|
---|
170 | }
|
---|
171 | #endregion
|
---|
172 | }
|
---|
173 | }
|
---|