mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-28 21:01:39 +03:00
Added tag tag1 for changeset 4c285537b335
This commit is contained in:
@@ -0,0 +1,151 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Security.Principal;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Routing;
|
||||
using System.Web.Security;
|
||||
using MyFriendsAround.Web.Models;
|
||||
|
||||
namespace MyFriendsAround.Web.Controllers
|
||||
{
|
||||
public class AccountController : Controller
|
||||
{
|
||||
|
||||
public IFormsAuthenticationService FormsService { get; set; }
|
||||
public IMembershipService MembershipService { get; set; }
|
||||
|
||||
protected override void Initialize(RequestContext requestContext)
|
||||
{
|
||||
if (FormsService == null) { FormsService = new FormsAuthenticationService(); }
|
||||
if (MembershipService == null) { MembershipService = new AccountMembershipService(); }
|
||||
|
||||
base.Initialize(requestContext);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/LogOn
|
||||
// **************************************
|
||||
|
||||
public ActionResult LogOn()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult LogOn(LogOnModel model, string returnUrl)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (MembershipService.ValidateUser(model.UserName, model.Password))
|
||||
{
|
||||
FormsService.SignIn(model.UserName, model.RememberMe);
|
||||
if (Url.IsLocalUrl(returnUrl))
|
||||
{
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
else
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("", "The user name or password provided is incorrect.");
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/LogOff
|
||||
// **************************************
|
||||
|
||||
public ActionResult LogOff()
|
||||
{
|
||||
FormsService.SignOut();
|
||||
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/Register
|
||||
// **************************************
|
||||
|
||||
public ActionResult Register()
|
||||
{
|
||||
ViewBag.PasswordLength = MembershipService.MinPasswordLength;
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public ActionResult Register(RegisterModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
// Attempt to register the user
|
||||
MembershipCreateStatus createStatus = MembershipService.CreateUser(model.UserName, model.Password, model.Email);
|
||||
|
||||
if (createStatus == MembershipCreateStatus.Success)
|
||||
{
|
||||
FormsService.SignIn(model.UserName, false /* createPersistentCookie */);
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("", AccountValidation.ErrorCodeToString(createStatus));
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
ViewBag.PasswordLength = MembershipService.MinPasswordLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/ChangePassword
|
||||
// **************************************
|
||||
|
||||
[Authorize]
|
||||
public ActionResult ChangePassword()
|
||||
{
|
||||
ViewBag.PasswordLength = MembershipService.MinPasswordLength;
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public ActionResult ChangePassword(ChangePasswordModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
if (MembershipService.ChangePassword(User.Identity.Name, model.OldPassword, model.NewPassword))
|
||||
{
|
||||
return RedirectToAction("ChangePasswordSuccess");
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
|
||||
}
|
||||
}
|
||||
|
||||
// If we got this far, something failed, redisplay form
|
||||
ViewBag.PasswordLength = MembershipService.MinPasswordLength;
|
||||
return View(model);
|
||||
}
|
||||
|
||||
// **************************************
|
||||
// URL: /Account/ChangePasswordSuccess
|
||||
// **************************************
|
||||
|
||||
public ActionResult ChangePasswordSuccess()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using GoogleMaps.Models;
|
||||
using MyFriendsAround.Data.BLL;
|
||||
|
||||
namespace MyFriendsAround.Web.Controllers
|
||||
{
|
||||
[HandleError]
|
||||
public class HomeController : Controller
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
ViewBag.Message = "Welcome to My Friends Around community site.";
|
||||
|
||||
return View();
|
||||
}
|
||||
|
||||
public ActionResult About()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[OutputCache(NoStore = true, Duration = 0)]
|
||||
public ActionResult GetMarkers()
|
||||
{
|
||||
// This would normally be our call to the Db, else we could populate this
|
||||
// with some data as Ive done here.
|
||||
MarkerList markers = GetMarkersObjects();
|
||||
|
||||
return Json(markers, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Gets the markers. This data could be filled with whatever you
|
||||
/// set from your DB.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static MarkerList GetMarkersObjects()
|
||||
{
|
||||
MarkerList list = new MarkerList();
|
||||
list.markers = new List<Marker>();
|
||||
|
||||
FriendsRepository.GetFriends().ForEach(f =>
|
||||
{
|
||||
Marker marker = new Marker
|
||||
{
|
||||
html = f.FriendName,
|
||||
lat = f.Latitude.ToString(),
|
||||
lng = f.Longitude.ToString(),
|
||||
label = f.FriendName
|
||||
};
|
||||
list.markers.Add(marker);
|
||||
});
|
||||
|
||||
return list;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user