signup and login
#region signup()
public ActionResult signup()
{
return View();
}
[HttpPost]
public JsonResult CheckRoleSignUpCredential(string signvalue, string signtype)
{
var previous_url = Request.UrlReferrer.PathAndQuery;
try
{
if (String.IsNullOrEmpty(signvalue))
return Json(new { redirect = previous_url, Result = "blank", Message = "" });
if (String.IsNullOrEmpty(signtype))
return Json(new { redirect = previous_url, Result = "blank", Message = "" });
return checkSignUpRole(signvalue, signtype, previous_url);
}
catch (Exception ex)
{
return Json(new { redirect = previous_url, Result = "error", Message = ex.Message });
}
}
public JsonResult checkSignUpRole(string signvalue, string signtype, string previous_url)
{
if (signtype == "sponsor_name")//CHECK SPONSOR
{
var _sponsor = dbContext.Agents.Where(x => x.LoginID.ToLower() == signvalue.ToLower().Trim()).Select(y => y).FirstOrDefault();
if (_sponsor != null)
return Json(new { redirect = previous_url, Result = "Ok", Message = _sponsor.Name });
else
return Json(new { redirect = previous_url, Result = "error", Message = "Referral Not Found!" });
}
else if (signtype == "user_name")//CHECK USER NAME
{
if (!dbContext.Agents.Where(x => x.LoginID.ToLower() == signvalue.ToLower().Trim()).Any())
return Json(new { redirect = previous_url, Result = "Ok", Message = "Available!" });
else
return Json(new { redirect = previous_url, Result = "error", Message = "Not Available!" });
}
else
return Json(new { redirect = previous_url, Result = "blank", Message = "" });
}
[HttpPost]
public JsonResult CreateRoleSignUpCredential(string pinnumber, string user_fullname, string user_mobile, string user_email,
string sponsor_name, string user_leglocation, string user_name, string user_password, string user_passwordrep, string country)
{
var previous_url = Request.UrlReferrer.PathAndQuery;
try
{
///********************CHECK SPONSOR DETAILS********************/
//if (String.IsNullOrEmpty(sponsor_name))
// return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter Sponsor ID" });
//if ((sponsor_name.Length < 6 || sponsor_name.Length > 10))
// return Json(new { redirect = previous_url, Result = "error", Message = "Sponsor User Name Should be Between 6-10 Characters" });
if (!String.IsNullOrEmpty(sponsor_name))
{
var _sponsor = dbContext.Agents.Where(x => x.LoginID.ToLower() == sponsor_name).Select(y => y).FirstOrDefault();
if (_sponsor == null)
return Json(new { redirect = previous_url, Result = "error", Message = "Referral ID not Exists" });
}
/********************CHECK SPONSOR DETAILS********************/
///*****CHECK LEG LOCATION*****/
//if (String.IsNullOrEmpty(user_leglocation) || user_leglocation.Trim() == "0")
// return Json(new { redirect = previous_url, Result = "error", Message = "Please Select Leg Location" });
/********************CHECK SPONSOR DETAILS********************/
///********************CHECK PIN DETAILS (IF EXISTS)********************/
//if (!String.IsNullOrEmpty(pinnumber))
//{
// var _pinDetails = dbContext.AgentPins.Where(x => x.PinNumber == pinnumber).Select(y => y).FirstOrDefault();
// if (_pinDetails == null)
// return Json(new { redirect = previous_url, Result = "error", Message = "Pin Number not Found" });
// if (_pinDetails.Status == "N")
// return Json(new { redirect = previous_url, Result = "error", Message = "Pin Number Already Used" });
// if (_pinDetails.AUID != _sponsor.AUID)
// return Json(new { redirect = previous_url, Result = "error", Message = "Sponsor not Associate with this Pin Number." });
//}
//else
//{
// return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter Pin Number" });
//}
/********************CHECK PIN DETAILS (IF EXISTS)********************/
/********************CHECK FULL NAME OF USER********************/
if (String.IsNullOrEmpty(user_fullname))
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter Your Full Name" });
/********************CHECK FULL NAME OF USER********************/
/********************CHECK USER EMAIL********************/
if (String.IsNullOrEmpty(user_email))
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User Email" });
/********************CHECK USER EMAIL********************/
/********************CHECK USER MOBILE********************/
if (String.IsNullOrEmpty(user_mobile))
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User Mobile" });
if (user_mobile.Length != 10)
return Json(new { redirect = previous_url, Result = "error", Message = "Mobile Number should be 10 Digits" });
if (_utility.isNumeric(user_mobile) == false)
return Json(new { redirect = previous_url, Result = "error", Message = "Mobile Number should be Numeric" });
if (dbContext.Agents.Where(x => x.Mobile.ToLower() == user_mobile.ToLower()).Any())
return Json(new { redirect = previous_url, Result = "error", Message = "User Mobile Already Registered, Try Again" });
/********************CHECK USER MOBILE********************/
/********************CHECK USER NAME********************/
//if (String.IsNullOrEmpty(user_name))
// return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User Name" });
//if ((user_name.Length < 6 || user_name.Length > 10))
// return Json(new { redirect = previous_url, Result = "error", Message = "User Name Should be Between 6-10 Characters" });
//if (dbContext.Agents.Where(x => x.LoginID.ToLower() == user_name.ToLower() && x.Role.ToLower() == "user").Any())
// return Json(new { redirect = previous_url, Result = "error", Message = "User Name Already Registered, Try Again" });
/********************CHECK USER NAME********************/
/********************CHECK USER PASSWORD********************/
if (String.IsNullOrEmpty(user_password))
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User Password" });
if (String.IsNullOrEmpty(user_passwordrep))
return Json(new { redirect = previous_url, Result = "error", Message = "Please Repeat Your Password" });
if ((user_password.Length < 4 || user_password.Length > 20) || (user_passwordrep.Length < 4 || user_passwordrep.Length > 20))
return Json(new { redirect = previous_url, Result = "error", Message = "User Password Should be Between 4-20 Characters" });
if (user_password != user_passwordrep)
return Json(new { redirect = previous_url, Result = "error", Message = "Repeat Password Does Not Match" });
/********************CHECK USER PASSWORD********************/
//GENERATE REFFRAL LINK
string _refferalLink = DateTime.UtcNow.TimeOfDay.ToString().Replace(":", "").Replace(".", "");
_refferalLink = _refferalLink + new Random().Next().ToString();
ObjectParameter _status = new ObjectParameter("Status", typeof(string));
ObjectParameter _message = new ObjectParameter("Message", typeof(string));
dbContext.Insert_Agent("SIGNUPR", _refferalLink, user_name, sponsor_name, "", user_leglocation, pinnumber.Trim(), user_passwordrep, user_fullname.ToUpper(), user_mobile, user_email.ToLower(), "", country, "",
Request.UserHostAddress, _status, _message);
if (_status.Value.ToString().ToLower() == "success")
{
string _loginID = _message.Value.ToString().ToLower();
var _agent = dbContext.Agents.Where(x => x.LoginID.ToLower() == _loginID).Select(y => y).FirstOrDefault();
if (!HttpContext.Request.IsLocal)
{
#region Send_SMS()
////string message = string.Format("Hi {0} thank you for signup acushine your user id {1} password {2} login for more details www.acushine.com", _agent.Name.ToUpper(), _agent.LoginID.ToUpper(), _agent.Password);
//string message = string.Format("Welcome to Grow India, Your Username- {0} & Password- {1} & Wallet Password:- {2}. Visit our website :https://acushine.com", _agent.Name.ToUpper(), _agent.Password, _agent.TransactionPassword);
//// use the API URL here
////string strUrl = string.Format("http://dnd.saakshisoftware.com/api/mt/SendSMS?user=demor&password=70627129&senderid=SAKSHI&channel=trans&DCS=0&flashsms=0&number={0}&text={1}&route=15", _agent.Mobile, message);
//string strUrl = string.Format("http://weberleads.in/http-tokenkeyapi.php?authentic-key=333567726f77696e64613538371608462495&senderid=GROWIN&route=2&number={0}&message={1}", _agent.Mobile, message);
//// Create a request object
//WebRequest request = HttpWebRequest.Create(strUrl);
//// Get the response back
//HttpWebResponse response = (HttpWebResponse)request.GetResponse();
//Stream s = (Stream)response.GetResponseStream();
//StreamReader readStream = new StreamReader(s);
//string dataString = readStream.ReadToEnd();
//response.Close();
//s.Close();
//readStream.Close();
#endregion
#region Send_EMAIL()
StreamReader reader;
reader = new StreamReader(Server.MapPath("/Content/Email/welcome.html"));
string readFile = reader.ReadToEnd();
string myString = "";
myString = readFile;
string subject = "Welcome Email from " + _CodeClass.GetCompanyName();
myString = myString.Replace("%{#{CompanyName}#}%", _CodeClass.GetCompanyName());
myString = myString.Replace("%{#{FullName}#}%", _agent.Name.ToUpper());
myString = myString.Replace("%{#{LoginID}#}%", _agent.LoginID.ToUpper());
myString = myString.Replace("%{#{Password}#}%", _agent.Password);
myString = myString.Replace("%{#{Mobile}#}%", _agent.Mobile);
_CodeClass.SendEMail(subject, myString, _agent.Email.Trim(), "");
#endregion
}
return Json(new
{
redirect = "/front/home/login",
Result = "Ok",
name = _agent.Name.ToUpper(),
loginid = _agent.LoginID.ToUpper(),
password = _agent.Password,
Message = "User Registered Successfully, Please Login to Continue!"
});
}
else
{
return Json(new { redirect = previous_url, Result = "error", Message = _message.Value.ToString() });
}
}
catch (Exception ex)
{
return Json(new { redirect = previous_url, Result = "error", Message = ex.Message });
}
}
#region login()
public ActionResult login()
{
//ViewBag.Recaptcha = ReCaptcha.GetHtml(ConfigurationManager.AppSettings["ReCaptcha:SiteKey"]);
//ViewBag.publicKey = ConfigurationManager.AppSettings["ReCaptcha:SiteKey"];
return View();
}
[HttpPost]
[ValidateHeaderAntiForgeryToken]
public JsonResult CheckUserCredential(string username, string password)
{
var previous_url = Request.UrlReferrer.PathAndQuery;
DateTime _currentDate = _utility.GetCurrentDate();
try
{
if (String.IsNullOrEmpty(username))
{
AgentLog _logerror = new AgentLog();
_logerror.LoginID = username;
_logerror.Password = password;
_logerror.IPAddress = HttpContext.Request.UserHostAddress;
_logerror.LoginDate = _currentDate;
_logerror.Remark = "Please Enter User ID";
dbContextError.AgentLogs.Add(_logerror);
dbContextError.SaveChanges();
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User ID!" });
}
if (String.IsNullOrEmpty(password))
{
AgentLog _logerror = new AgentLog();
_logerror.LoginID = username;
_logerror.Password = password;
_logerror.IPAddress = HttpContext.Request.UserHostAddress;
_logerror.LoginDate = _currentDate;
_logerror.Remark = "Please Enter User Password";
dbContextError.AgentLogs.Add(_logerror);
dbContextError.SaveChanges();
return Json(new { redirect = previous_url, Result = "error", Message = "Please Enter User Password!" });
}
var _agent = dbContext.Agents.Where(x => x.LoginID.ToLower() == username.ToLower().Trim() && x.Password == password && x.Role.ToLower() == "user").Select(y => y).FirstOrDefault();
if (_agent == null)
{
AgentLog _logerror = new AgentLog();
_logerror.LoginID = username;
_logerror.Password = password;
_logerror.IPAddress = HttpContext.Request.UserHostAddress;
_logerror.LoginDate = _currentDate;
_logerror.Remark = "InValid Login Credentials";
dbContextError.AgentLogs.Add(_logerror);
dbContextError.SaveChanges();
return Json(new { redirect = previous_url, Result = "error", Message = "InValid Login Credentials!" });
}
if (_agent.LoginCount > 0)
{
AgentLog _logerror = new AgentLog();
_logerror.LoginID = username;
_logerror.Password = password;
_logerror.IPAddress = HttpContext.Request.UserHostAddress;
_logerror.LoginDate = _currentDate;
_logerror.Remark = "Your Account is blocked";
dbContextError.AgentLogs.Add(_logerror);
dbContextError.SaveChanges();
return Json(new { redirect = previous_url, Result = "error", Message = "Your Account is blocked!" });
}
string _isPrime = "0";
if (_agent.IsPinUsed.Value == true && _agent.IsPinUsedValidTill.Value >= _currentDate)
_isPrime = "1";
HttpCookie _cookie = new HttpCookie("_cmU");
_cookie["_cmUwP"] = "USER";
_cookie["_cmUuN"] = _agent.AUID.ToString();
_cookie["_cmUuR"] = _agent.Role;
_cookie["_cmUuPr"] = _isPrime;
_cookie["_cmUuS"] = _agent.LoginID;
_cookie.Expires = Convert.ToDateTime(_currentDate.ToString("dd-MM-yyyy") + " 23:59:59");
System.Web.HttpContext.Current.Response.Cookies.Add(_cookie);
SiteSession.websitePanel = "USER";
SiteSession.UserName = _agent.AUID.ToString();
SiteSession.UserRole = _agent.Role;
SiteSession.IsUserPrime = _isPrime;
SiteSession.UserSession = _agent.LoginID;
AgentLog _log = new AgentLog();
_log.LoginID = _agent.LoginID;
_log.Password = "";
_log.IPAddress = HttpContext.Request.UserHostAddress;
_log.LoginDate = _currentDate;
_log.Remark = "LOGIN SUCCESSFUL";
dbContextError.AgentLogs.Add(_log);
dbContextError.SaveChanges();
return Json(new { redirect = "/front/home/products", Result = "Ok", Message = "Please wait we are checking !" });
}
catch (Exception ex)
{
AgentLog _logerror = new AgentLog();
_logerror.LoginID = username;
_logerror.Password = password;
_logerror.IPAddress = HttpContext.Request.UserHostAddress;
_logerror.LoginDate = _currentDate;
_logerror.Remark = ex.Message;
dbContextError.AgentLogs.Add(_logerror);
dbContextError.SaveChanges();
return Json(new { redirect = previous_url, Result = "error", Message = ex.Message });
}
}
#endregion
==================== filters
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Data;
using System.Web.Routing;
using System.Web.Helpers;
using System.Text.RegularExpressions;
using biddergo.Models;
using biddergo.Utilities;
namespace biddergo.Areas.Front.Filter
{
public class FrontAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
var descriptor = filterContext.ActionDescriptor;
var actionName = descriptor.ActionName;
var controllerName = descriptor.ControllerDescriptor.ControllerName;
string Path = filterContext.RouteData.DataTokens["area"].ToString() + "/" + controllerName + "/" + actionName;
HttpCookie _cookie = filterContext.HttpContext.Request.Cookies.Get("_bgU");
biddergoEntities dbcontext = new biddergoEntities();
if (_cookie != null && SiteSession.UserName == null)
{
Guid _AUID = Guid.NewGuid();
Guid.TryParse(_cookie["_bgUuN"].ToString(), out _AUID);
if (dbcontext.Agents.Where(x => x.AUID == _AUID).Any())
{
SiteSession.websitePanel = _cookie["_bgUwP"];
SiteSession.UserName = _cookie["_bgUuN"];
SiteSession.UserRole = _cookie["_bgUuR"];
SiteSession.UserSession = _cookie["_bgUuS"];
}
}
if (SiteSession.UserName != null)
{
if (actionName.ToLower() != "unauthorized")
{
if (actionName.ToLower() == "logout")
{
HttpContext.Current.Session.RemoveAll();
HttpContext.Current.Session.Abandon();
HttpCookie _cookie2 = filterContext.HttpContext.Request.Cookies.Get("_bgU");
if (_cookie2 != null)
{
_cookie2.Expires = DateTime.Now.AddYears(-10);
filterContext.HttpContext.Response.AppendCookie(_cookie2);
}
SiteSession.UserName = null;
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Home", action = "index", area = "Front" }));
}
}
}
else
{
if (controllerName.ToLower() == "user")
{
filterContext.Result = new RedirectToRouteResult(new RouteValueDictionary(new { controller = "Home", action = "UnAuthorizedNonLogin", area = "Front" }));
}
}
}
public override void OnActionExecuted(ActionExecutedContext filterContext)
{
}
public override void OnResultExecuting(ResultExecutingContext filterContext)
{
}
public override void OnResultExecuted(ResultExecutedContext filterContext)
{
}
}
}
======================= project.utilities
using System.Web;
namespace acushine.Utilities
{
public class SiteSession
{
public static string websitePanel
{
get { return (string)HttpContext.Current.Session["websitePanel"]; }
set { HttpContext.Current.Session["websitePanel"] = value; }
}
public static string UserName
{
get { return (string)HttpContext.Current.Session["userName"]; }
set { HttpContext.Current.Session["userName"] = value; }
}
public static string UserRole
{
get { return HttpContext.Current.Session["userRole"] == null ? "" : (string)HttpContext.Current.Session["userRole"]; }
set { HttpContext.Current.Session["userRole"] = value; }
}
public static string UserSession
{
get { return HttpContext.Current.Session["userSession"] == null ? null : (string)HttpContext.Current.Session["userSession"]; }
set { HttpContext.Current.Session["userSession"] = value; }
}
public static string IsUserPrime
{
get { return HttpContext.Current.Session["isUserPrime"] == null ? "0" : (string)HttpContext.Current.Session["isUserPrime"]; }
set { HttpContext.Current.Session["isUserPrime"] = value; }
}
public static string NotAuthorized
{
get { return HttpContext.Current.Session["NotAuthorized"] == null ? "" : (string)HttpContext.Current.Session["NotAuthorized"]; }
set { HttpContext.Current.Session["NotAuthorized"] = value; }
}
}
}
#endregion
Comments
Post a Comment