Browse Source

Fixed redirect after Registration

tags/2.0.3
Teknikode 4 years ago
parent
commit
a0ef38eb7f

+ 20
- 3
Teknik/Areas/Profile/Controllers/ProfileController.cs View File

@@ -4,6 +4,8 @@ using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using Teknik.Areas.Blog.Models;
using Teknik.Areas.Profile.Models;
using Teknik.Areas.Profile.ViewModels;
using Teknik.Controllers;
using Teknik.Helpers;
@@ -83,11 +85,26 @@ namespace Teknik.Areas.Profile.Controllers
{
return Json(new { error = "Passwords must match." });
}
if (model.Insert())
try
{
return RedirectToAction("Login", "Profile", new LoginViewModel { Username = model.Username, Password = model.Password });
// Add User
User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now;
newUser.Username = model.Username;
newUser.HashedPassword = SHA384.Hash(model.Username, model.Password);
db.Users.Add(newUser);
db.SaveChanges();

// Generate blog for the user
var newBlog = db.Blogs.Create();
newBlog.UserId = db.Users.Where(u => u.Username == model.Username).Select(u => u.UserId).First();
db.SaveChanges();
}
catch (Exception ex)
{
return Json(new { error = "Unable to create the user." });
}
return Json(new { error = "You must include all fields." });
return Login(new LoginViewModel { Username = model.Username, Password = model.Password, RememberMe = false });
}
return Json(new { error = "You must include all fields." });
}

+ 0
- 20
Teknik/Areas/Profile/ViewModels/RegisterViewModel.cs View File

@@ -23,25 +23,5 @@ namespace Teknik.Areas.Profile.ViewModels
[Display(Name = "Confirm Password")]
[DataType(DataType.Password)]
public string ConfirmPassword { get; set; }

public bool Insert()
{
bool success = true;
try
{
User newUser = db.Users.Create();
newUser.JoinDate = DateTime.Now;
newUser.Username = Username;
newUser.HashedPassword = SHA384.Hash(Username, Password);
db.Users.Add(newUser);
db.SaveChanges();
}
catch (Exception ex)
{
success = false;
}

return success;
}
}
}

Loading…
Cancel
Save