129 lines
4.4 KiB
C#
129 lines
4.4 KiB
C#
//-----------------------------------------------------------------------
|
|
// <copyright file="UserController.cs" company="CCPL">
|
|
// Copyright (c) CCPL. All rights reserved.
|
|
// </copyright>
|
|
// <author>Jitendra Tiwari</author>
|
|
//--------------------------------
|
|
namespace WEBAPP._2012.Controllers
|
|
{
|
|
using LoggingHelper;
|
|
using System;
|
|
using System.Configuration;
|
|
using System.Web.Mvc;
|
|
using GODATA.AuthenticationServices;
|
|
using GODATA.Models;
|
|
|
|
|
|
/// <summary>
|
|
/// Class for user management.
|
|
/// </summary>
|
|
///
|
|
[GODATA.MvcApplication.SessionExpire]
|
|
public class UserController : Controller
|
|
{
|
|
#region Global Variables
|
|
|
|
/// <summary>
|
|
/// Represent object of LoggingUtility class
|
|
/// </summary>
|
|
LoggingUtility objLog = new LoggingUtility();
|
|
|
|
/// <summary>
|
|
/// Represent string object contain log file path
|
|
/// </summary>
|
|
string path = System.Web.HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PathLog"]);
|
|
|
|
/// <summary>
|
|
/// Represent string object contain log status
|
|
/// </summary>
|
|
string logtf = (ConfigurationManager.AppSettings["Log"]);
|
|
|
|
/// <summary>
|
|
/// Represent string object contain Error log status
|
|
/// </summary>
|
|
string errorlogtf = (ConfigurationManager.AppSettings["ErrorLog"]);
|
|
|
|
/// <summary>
|
|
/// it's get application name from web.config file.
|
|
/// </summary>
|
|
private static string _appName = ConfigurationManager.AppSettings["ApplicationName"].ToString();
|
|
#endregion
|
|
|
|
/// <summary>
|
|
/// GET : User/Index
|
|
/// </summary>
|
|
/// <returns>Action Result</returns>
|
|
|
|
public ActionResult Index()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
#region Actions - Change Password
|
|
|
|
/// <summary>
|
|
/// GET: /Account/ChangePassword
|
|
/// </summary>
|
|
/// <returns>Action Result</returns>
|
|
|
|
public ActionResult ChangePassword()
|
|
{
|
|
return View();
|
|
}
|
|
|
|
/// <summary>
|
|
/// POST: /Account/ChangePassword
|
|
/// </summary>
|
|
/// <param name="model">Change Password Model</param>
|
|
/// <returns>Action Result</returns>
|
|
[HttpPost]
|
|
|
|
public ActionResult ChangePassword(ChangePasswordModel model)
|
|
{
|
|
objLog.AddLogFile("ChangePassword", DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
|
|
if (ModelState.IsValid)
|
|
{
|
|
bool changePasswordSucceeded;
|
|
try
|
|
{
|
|
UserClient oUserClient = new UserClient();
|
|
changePasswordSucceeded = oUserClient.ChangePasswordByApplication(User.Identity.Name, model.OldPassword, model.NewPassword, _appName);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
changePasswordSucceeded = false;
|
|
objLog.ErrorLogFile("ChangePassword", ex.Message, path, errorlogtf);
|
|
objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
|
|
ModelState.AddModelError(string.Empty, ex.Message);
|
|
}
|
|
|
|
if (changePasswordSucceeded)
|
|
{
|
|
objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
|
|
return RedirectToAction("ChangePasswordSuccess");
|
|
}
|
|
else
|
|
{
|
|
objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
|
|
ModelState.AddModelError(string.Empty, "The current password is incorrect or the new password is invalid.");
|
|
}
|
|
}
|
|
|
|
////If we got this far, something failed, redisplay form
|
|
objLog.AddLogFile(DateTime.Now.ToString(ConfigurationManager.AppSettings["dateTimeFormat"]), path, logtf);
|
|
return View(model);
|
|
}
|
|
|
|
/// <summary>
|
|
/// GET: /Account/ChangePasswordSuccess
|
|
/// </summary>
|
|
/// <returns>Action Result</returns>
|
|
|
|
public ActionResult ChangePasswordSuccess()
|
|
{
|
|
return View();
|
|
}
|
|
#endregion
|
|
}
|
|
}
|