Exemple #1
0
        public JsonResult CreateAdmin(AdminRegisterViewModel model)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                try
                {
                    List <Core.Domain.Users> list    = _manageAdminAPIController.GetUsersByEmail(model.UserName.ToString());
                    Core.Domain.Users        userobj = new Core.Domain.Users();
                    userobj.FirstName       = model.FirstName;
                    userobj.LastName        = model.LastName;
                    userobj.IndustryId      = model.IndustryName;
                    userobj.IsDeleted       = false;
                    userobj.Password        = smartData.Common.CommonFunction.Encrypt(model.Password);
                    userobj.ConfirmPassword = smartData.Common.CommonFunction.Encrypt(model.ConfirmPassword);
                    userobj.CreatedBy       = smartData.Common.SessionManager.LoggedInUser.UserID;
                    userobj.Email           = model.UserName;
                    var addAdmin = _userService.AddUser(userobj);

                    //int _userID = WebSecurity.GetUserId(model.UserName);
                    //if (list.Count == 0 && _userID > 0)
                    //{
                    //    ((SimpleMembershipProvider)Membership.Provider).DeleteUser(model.UserName.ToString(), true); // deletes record from webpages_Membership table
                    //}
                    //WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { FirstName = model.FirstName, LastName = model.LastName, UserType = 2 });
                    status = true;
                }
                catch (Exception ex)
                {
                    status = false;
                }
            }
            return(Json(new { status = status }, JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public ActionResult LoginAdmin(string email, string password, int industryId)
        {
            var currentUser = smartData.Common.SessionManager.LoggedInUser.UserID;

            //List<Core.Domain.Users> list = _userService.GetUsersByEmail(email);
            Core.Domain.Users list = _manageAdminService.GetUserByEmailandIndustryId(email, industryId);
            if (list != null)//list.Count > 0
            {
                Core.Domain.Users _objuser = list;
                var user = _userService.AuthenticateUser(email, industryId, _objuser.Password);

                if (user != null)
                {
                    int            cID   = WebSecurity.GetUserId(email);
                    LoginViewModel model = new LoginViewModel();
                    model.UserName = email;
                    model.Password = password;
                    CreateAuthenticateFormsTicket(model);
                    var HasProfileImage = _objuser.Photo == null ? false : true;
                    SessionManager.FillSession(_objuser.UserId, _objuser.FirstName, _objuser.LastName, _objuser.Email, Convert.ToInt32(_objuser.UserTypeId), HasProfileImage, user.IndustryId, currentUser);
                    return(RedirectToAction("Index", "Home", new { @Area = "Users" }));
                }
            }
            return(View());
        }
        public ActionResult AddRssFeed(string FeedName, string FeedUrl, int UserId)
        {
            Core.Domain.Users user = _usersAPIController.GetUserByID(UserId);
            bool status            = _manageRssFeedAPIController.AddRssFeed(FeedName, FeedUrl, UserId, user);

            return(Json(new { status = status }));
        }
Exemple #4
0
        public bool AddRss(string FeedName, string Feed, int UserId, Core.Domain.Users user)
        {
            bool status = false;

            try
            {
                smRssFeeds feed = new smRssFeeds();
                feed.FeedName    = FeedName;
                feed.FeedUrl     = Feed;
                feed.UserId      = UserId;
                feed.CreatedBy   = user.FirstName + " " + user.LastName;
                feed.CreatedDate = DateTime.UtcNow;
                if (user.UserTypeId == 3)
                {
                    feed.UserType   = "SuperAdmin";
                    feed.IsApproved = true;
                }
                else
                {
                    feed.UserType   = "Admin";
                    feed.IsApproved = false;
                }
                feed.IsActive  = true;
                feed.IsDeleted = false;
                Context.Set <smRssFeeds>().Add(feed);
                Context.SaveChanges();
                status = true;
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(status);
        }
Exemple #5
0
 public ActionResult Edit([Bind(Include = "UserId,FirstName,LastName,Email,Password,ConfirmPassword,ModifiedBy")] Core.Domain.Users user)
 {
     if (ModelState.IsValid)
     {
         user.ModifiedBy = WebSecurity.CurrentUserId;
         _usersAPIController.EditUser(user);
         return(RedirectToAction("Index"));
     }
     return(View(user));
 }
Exemple #6
0
 // GET: /Users/Users/Details/5
 public ActionResult Details(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Core.Domain.Users user = _userService.GetUserById(id);
     if (user == null)
     {
         return(HttpNotFound());
     }
     return(View(user));
 }
Exemple #7
0
 // GET: /Users/Users/Delete/5
 public ActionResult Delete(int?id)
 {
     if (id == null)
     {
         return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
     }
     Core.Domain.Users user = _usersAPIController.GetUserByID(id);
     if (user == null)
     {
         return(HttpNotFound());
     }
     return(View(user));
 }
Exemple #8
0
        public JsonResult GetPassword(int id)
        {
            bool   status   = false;
            string password = string.Empty;

            try
            {
                Core.Domain.Users user = _manageUserAPIController.GetPassword(id);
                password = smartData.Common.CommonFunction.Decrypt(user.Password);
                status   = true;
            }
            catch (Exception ex)
            {
                status = false;
            }
            return(Json(new { status = status, password = password }, JsonRequestBehavior.AllowGet));
        }
Exemple #9
0
        // [ValidateAntiForgeryToken]
        public ActionResult ChangePasswordAdmin()
        {
            ModelState.Clear();
            ChangePasswordModel model = new ChangePasswordModel();

            TempData["token"]    = Request.QueryString["token"];
            TempData["username"] = Request.QueryString["Username"];
            Core.Domain.Users list = _manageAdminService.GetUserByEmailandIndustryId(TempData["username"].ToString(), Convert.ToInt32(Request.QueryString["token"]));
            var objuser            = list;

            if (objuser.LastChangePasswordDate < DateTime.UtcNow)
            {
                TempData["Message"] = "Your forgot password link has been expire.";
                return(View("LinkExpire"));
            }
            else
            {
                return(View());
            }
        }
Exemple #10
0
        public bool DeleteUser(int id)
        {
            bool deleteAcntRes;

            Core.Domain.Users user = _userService.GetUserById(id);
            var res = _userService.DeleteUser(id);

            // Delete user account from webpages_Membership table
            if (res)
            {
                if (user != null)
                {
                    if (((WebMatrix.WebData.SimpleMembershipProvider)Membership.Provider).HasLocalAccount(user.UserId))
                    {
                        deleteAcntRes = ((WebMatrix.WebData.SimpleMembershipProvider)Membership.Provider).DeleteAccount(user.Email);
                    }
                }
            }
            return(res);
        }
Exemple #11
0
        public string GetUserByEmail(string email, int id)
        {
            List <Core.Domain.Users> Users = _userService.GetUsersByEmail(email);

            Core.Domain.Users _objuser = Users.FirstOrDefault();
            if (_objuser != null)
            {
                if (_objuser.UserId == id)
                {
                    return("");
                }
                else
                {
                    return("exists");
                }
            }
            else
            {
                return("");
            }
        }
Exemple #12
0
        public ActionResult Create([Bind(Include = "UserId,FirstName,LastName,Email,RoleIDs,Password,ConfirmPassword,IsSuperAdmin")] UserInsert user)
        {
            //if (user.RoleIDs == null)
            //{
            //    return Content("Please Select Role.");
            //}
            user.RolesList      = _userService.GetAllRoles();
            ViewData["AllRole"] = _userService.GetAllRoles();
            if (ModelState.IsValid)
            {
                user.Active = true;
                Core.Domain.Users _usersObject = null;
                try
                {
                    _usersObject = _usersAPIController.Create(user);
                    WebSecurity.CreateAccount(_usersObject.Email, _usersObject.Password);
                    return(RedirectToAction("Index"));
                }
                catch (Exception ex)
                {
                    ViewBag.logUser = WebSecurity.CurrentUserId;
                    UserInsert obj = new UserInsert();
                    obj.RolesList = _userService.GetAllRoles();

                    List <Core.Domain.Users> list = _userService.GetUsersByEmail(user.Email.ToString());
                    if (list.Count > 0)
                    {
                        //_userService.DeleteUser(_usersObject.UserId);
                        return(Content("This email is already registered"));
                    }
                    return(View("Index", obj));
                }
            }
            else
            {
                var avc = ModelState.Values.Select(x => x.Errors);
            }
            return(View("Index", user));
            // return null;
        }
Exemple #13
0
        public ActionResult ChangePasswordAdmin(ChangePasswordModel model)
        {
            string user     = Request.QueryString["Username"];
            string UserName = Convert.ToString(TempData["usernames"]);
            string token    = Convert.ToString(TempData["token"]);

            //List<Core.Domain.Users> list = _userService.GetUsersByEmail(model.UserName);
            Core.Domain.Users list = _manageAdminService.GetUserByEmailandIndustryId(model.UserName, model.InustryId);

            ///var user = _manageAdminService.GetUserByEmailandIndustryId(UserName, model.IndustryId);
            //var objuser = list.FirstOrDefault();
            var objuser = list;

            if (objuser.LastChangePasswordDate < DateTime.UtcNow)
            {
                TempData["Message"] = "Your forgot password link has been expire.";
                return(RedirectToAction("Login"));
            }
            if (objuser != null)
            {
                try
                {
                    objuser.Password        = smartData.Common.CommonFunction.Encrypt(model.NewPassword);
                    objuser.ConfirmPassword = smartData.Common.CommonFunction.Encrypt(model.ConfirmPassword);
                    var addAdmin = _userService.UpdateUsers(objuser);
                    TempData["Message"] = CustomMessages.PasswordChanged;
                }
                catch (Exception ex)
                {
                    TempData["Message"] = CustomMessages.ErrorWhileChangingPassword + ex.Message;
                }
            }
            else
            {
                TempData["Message"] = "Email does not Exists";
            }

            //string token = Convert.ToString(TempData["token"]);
            //string UserName = Convert.ToString(TempData["username"]);
            //// string token = "iwoAq_I03EcLHVcQtNHDPA2";
            //// string UserName = "******";
            //bool any = _userService.UpdatePassword(UserName, token);
            //bool response = false;
            //if (any == true)
            //{
            //    response = WebSecurity.ResetPassword(token, model.NewPassword);
            //    if (response == true)
            //    {
            //        try
            //        {
            //            //  Here Maintain Password History
            //            //  MembershipUser u = Membership.GetUser(WebSecurity.CurrentUserName, false);

            //            string RetPassword = HashData(model.NewPassword);
            //            SecUserPasswordHistory _secUserPasswordHistory = new SecUserPasswordHistory();
            //            byte[] array = Encoding.ASCII.GetBytes(RetPassword);

            //            _secUserPasswordHistory.PasswordHash256 = array;
            //            _secUserPasswordHistory.DeleteFlag = false;
            //            _secUserPasswordHistory.RowVersion = null;
            //            _secUserPasswordHistory.SecUserID = (WebSecurity.CurrentUserId);
            //            _userService.AddPasswordHistory(_secUserPasswordHistory);
            //            TempData["Message"] = CustomMessages.PasswordChanged;
            //            // return Content(CustomMessages.PasswordChanged);
            //        }
            //        catch (Exception ex)
            //        {
            //            TempData["Message"] = CustomMessages.ErrorWhileChangingPassword + ex.Message;
            //        }
            //    }
            //    else
            //    {
            //        TempData["Message"] = CustomMessages.HeyAvoidRandomRequest;
            //    }
            //}
            //else
            //{
            //    TempData["Message"] = CustomMessages.UserAndTokenNotMatch;
            //}
            return(RedirectToAction("Login"));
        }
Exemple #14
0
        public JsonResult CreateAdmin(AdminRegisterViewModel model)
        {
            bool status = false;

            if (ModelState.IsValid)
            {
                try
                {
                    if (smartData.Common.SessionManager.LoggedInUser.UserType == 2)
                    {
                        model.IndustryName = smartData.Common.SessionManager.LoggedInUser.IndustryId;
                    }

                    List <Core.Domain.Users> list = _manageUserAPIController.GetUsersByEmail(model.UserName.ToString());
                    var industry = _manageCategoryService.GetIndustryById(Convert.ToInt32(model.IndustryName));
                    Core.Domain.Users userobj = new Core.Domain.Users();
                    userobj.FirstName    = model.FirstName;
                    userobj.LastName     = model.LastName;
                    userobj.IndustryId   = Convert.ToInt32(model.IndustryName);
                    userobj.IndustryName = industry.IndustryName;
                    userobj.IsDeleted    = false;
                    if (smartData.Common.SessionManager.LoggedInUser.UserType == 2)
                    {
                        userobj.UserTypeId = 1;//admin
                    }
                    else
                    {
                        userobj.UserTypeId = model.UserType;
                    }
                    string pass   = "";
                    Random random = new Random();
                    int    length = 8;
                    for (int i = 0; i < length; i++)
                    {
                        if (random.Next(0, 3) == 0)                     //if random.Next() == 0 then we generate a random character
                        {
                            pass += ((char)random.Next(65, 91)).ToString();
                        }
                        else                                            //if random.Next() == 0 then we generate a random digit
                        {
                            pass += random.Next(0, 9);
                        }
                    }


                    userobj.Password        = smartData.Common.CommonFunction.Encrypt(pass);
                    userobj.ConfirmPassword = smartData.Common.CommonFunction.Encrypt(pass);
                    userobj.Active          = true;
                    userobj.CreatedBy       = smartData.Common.SessionManager.LoggedInUser.UserID;
                    userobj.CreatedDate     = DateTime.UtcNow;
                    userobj.Email           = model.UserName;
                    var addAdmin = _userService.AddUser(userobj);
                    var Role     = "";
                    if (userobj.UserTypeId == 1)
                    {
                        Role = "User";
                    }
                    else
                    {
                        Role = "Admin";
                    }
                    #region strbody for email
                    var ReturnUrl = "";
                    if (model.UserType == 1)
                    {
                        ReturnUrl = "http://sm4y.cc/" + addAdmin.IndustryName + "/login";
                    }
                    else
                    {
                        ReturnUrl = "http://sm4y.cc/admin";
                    }


                    string strBody = string.Empty;
                    strBody = "<body marginwidth='0' marginheight='0' offset='0' topmargin='0' leftmargin='0'>" +
                              "<center>" +
                              "<table id='bodyTable' width='100%' cellspacing='0' cellpadding='0' border='0' align='center' height='100%' style='background-color: #dee0e2;'>" +
                              "<tbody>" +
                              "<tr>" +
                              "<td id='bodyCell' valign='top' align='center' style='border-top: 4px solid #bbbbbb; padding: 20px;'>" +
                              "<table cellspacing='0' cellpadding='0' border='0' style='border: 1px solid #bbbbbb; width: 600px;'>" +
                              "<tbody>" +
                              // GetHeaderString() +
                              "<tr>" +
                              "<td valign='top' align='center'>" +
                              "<table id='templateBody' width='100%' cellspacing='0' cellpadding='0' border='0' style='background-color: #f4f4f4; border-bottom: 1px solid #cccccc;  border-top: 1px solid #ffffff;'>" +
                              "<tbody>" +
                              "<tr>" +
                              "<td class='bodyContent' valign='top' mc:edit='body_content' style='color: #505050;font-family: Helvetica;font-size: 16px;line-height: 150%; padding: 20px; text-align: left;'>" +
                              "<h1 style='color: #202020 !important; font-size: 26px; line-height: 100%; margin: 0 0 10px; '>" + model.FirstName + " " + model.LastName + ",</h1>" +
                              "<br />" +
                              "Your " + System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + " account was setup successfully. " + "<br />" +
                              "To access your account go to <a href='" + ReturnUrl + "'>" + ReturnUrl + "</a> and use the following credentials: " + "<br /><br />" +
                              "<strong>Username :</strong> " + "  " + "" + model.UserName + "<br />" +
                              "<strong>Password :</strong> " + "  " + "" + pass + "<br /><br/>" +
                              "Thank you for your business.<br />" +
                              "We look forward to connect your Social Media audience with valuable information.<br />" +
                              "<br />" +
                              "Regards," +
                              "<br />" +
                              "" + System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + " Team" +
                              " </td>" +
                              "</tr>" +
                              "</tbody>" +
                              "</table>" +
                              " </td>" +
                              "</tr>" +
                              // GetFooterString() +
                              "</tbody>" +
                              "</table>" +
                              "</td>" +
                              "</tr>" +
                              "</tbody>" +
                              "</table>" +
                              "</center>" +
                              "</body>";
                    #endregion
                    CommonFunctions.SendEmail(model.UserName, "Welcome to " + System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + "", strBody);

                    //int _userID = WebSecurity.GetUserId(model.UserName);
                    //   if (list.Count == 0 && _userID > 0)
                    //{
                    //    ((SimpleMembershipProvider)Membership.Provider).DeleteUser(model.UserName.ToString(), true); // deletes record from webpages_Membership table
                    //}
                    //WebSecurity.CreateUserAndAccount(model.UserName, model.Password, propertyValues: new { FirstName = model.FirstName, LastName = model.LastName, UserType = 2,    IndustryName = model.IndustryName });
                    status = true;
                }
                catch (Exception ex)
                {
                    status = false;
                }
            }
            return(Json(new { status = status }, JsonRequestBehavior.AllowGet));
        }
Exemple #15
0
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            List <smIndustry> newlist = _manageContentService.GetCategories();

            ViewBag.IndustryName = new SelectList(newlist, "IndustryId", "IndustryName");
            // ServiceLayer.Services.ScreenPermissionService _ActionAccessPermissionService = new ServiceLayer.Services.ScreenPermissionService();

            //// If we got this far, something failed, redisplay form
            //return View(model);

            if (ModelState.IsValid)
            {
                // ServiceLayer.Services.ResetPasswordService _ResetPasswordService = new ServiceLayer.Services.ResetPasswordService();
                List <Core.Domain.Users> list = _userService.GetUsersByEmail(model.UserName.ToString());
                if (list.Count > 0)
                {
                    Core.Domain.Users _objuser = list.FirstOrDefault();
                    var pass = smartData.Common.CommonFunction.Encrypt(model.Password);
                    Core.Domain.Users user = null;
                    if (_objuser.IsSuperAdmin == true && model.IndustryId == 0)
                    {
                        user = _userService.AuthenticateSuperAdmin(model.UserName, pass);
                    }

                    else
                    {
                        user = _userService.AuthenticateUser(model.UserName, model.IndustryId, pass);
                    }

                    if (user != null)
                    {
                        int    cID     = WebSecurity.GetUserId(model.UserName);
                        string TokenID = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                        Session["TokenID"] = TokenID;
                        if (_objuser.UserTypeId == 1)
                        {
                            ViewBag.ErrMessage = true;
                            return(View());
                        }
                        else
                        {
                            if (Session["TokenID"].ToString() == "")
                            {
                                TokenID            = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                                Session["TokenID"] = TokenID;
                            }
                            if (model.RememberMe)
                            {
                                CreateAuthenticateFormsTicket(model);
                            }
                            CreateAuthenticateFormsTicket(model);
                            if (returnUrl != null && returnUrl != "/")
                            {
                                return(Redirect(returnUrl));
                            }
                            var ProfileImage = _objuser.Photo == null ? false : true;
                            //Fill session accordin to the user type.
                            SessionManager.FillAdminSession(_objuser.UserId, _objuser.FirstName, _objuser.LastName, _objuser.Email, Convert.ToInt32(_objuser.UserTypeId), ProfileImage, _objuser.IsSuperAdmin, model.IndustryId);
                            GlobalVar.Insudtry = smartData.Common.SessionManager.LoggedInUser.IndustryId;
                            GlobalVar.userType = smartData.Common.SessionManager.LoggedInUser.UserType;
                            ViewData.Add("FullName", list[0].FirstName + " " + list[0].LastName);
                            return(RedirectToRoute("AdminDashboardRoute"));
                        }
                    }
                    //if (WebSecurity.Login(model.UserName, model.Password))
                    //{

                    //}
                    else
                    {
                        TempData["Message"] = "errorInvalidUser";
                        //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                        return(View(model));
                    }
                }
                else
                {
                    TempData["Message"] = "errorInvalidUser";
                    //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                    return(View(model));
                }
            }
            TempData["Message"] = "errorInvalidUser";
            //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
            return(View(model));
        }
 public bool AddRssFeed(string FeedName, string FeedUrl, int UserId, Core.Domain.Users user)
 {
     return(_manageRssFeedservice.AddRss(FeedName, FeedUrl, UserId, user));
 }
Exemple #17
0
        public ActionResult SwitchSuperAdminLogin(string UserName, string Password, string IndustryId)
        {
            List <smIndustry> newlist = _manageContentService.GetCategories();

            ViewBag.IndustryName = new SelectList(newlist, "IndustryId", "IndustryName");
            LoginViewModel model = new LoginViewModel();

            model.IndustryId = Convert.ToInt32(IndustryId);
            model.UserName   = UserName;
            model.Password   = Password;
            model.RememberMe = true;
            if (ModelState.IsValid)
            {
                // ServiceLayer.Services.ResetPasswordService _ResetPasswordService = new ServiceLayer.Services.ResetPasswordService();
                Core.Domain.Users list = _manageAdminService.GetUserByEmailandIndustryId(UserName, model.IndustryId);
                if (list != null) //list.Count > 0
                {
                    Core.Domain.Users _objuser = list;
                    var pass = list.Password;
                    Core.Domain.Users user = null;
                    if (_objuser.IsSuperAdmin == true && model.IndustryId == 0)
                    {
                        user = _userService.AuthenticateSuperAdmin(UserName, pass);
                    }

                    else
                    {
                        user = _userService.AuthenticateUser(UserName, model.IndustryId, pass);
                    }

                    if (user != null)
                    {
                        int    cID     = WebSecurity.GetUserId(UserName);
                        string TokenID = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                        Session["TokenID"] = TokenID;
                        if (_objuser.UserTypeId == 1)
                        {
                            ViewBag.ErrMessage = true;
                            return(View());
                        }
                        else
                        {
                            if (Session["TokenID"].ToString() == "")
                            {
                                TokenID            = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                                Session["TokenID"] = TokenID;
                            }
                            //CreateAuthenticateFormsTicket(model);
                            //if (returnUrl != null && returnUrl != "/")
                            //{
                            //    return Redirect(returnUrl);
                            //}
                            var ProfileImage = _objuser.Photo == null ? false : true;
                            //Fill session accordin to the user type.
                            SessionManager.FillAdminSession(_objuser.UserId, _objuser.FirstName, _objuser.LastName, _objuser.Email, Convert.ToInt32(_objuser.UserTypeId), ProfileImage, _objuser.IsSuperAdmin, model.IndustryId);

                            //ViewData.Add("FullName", list[0].FirstName + " " + list[0].LastName);
                            ViewData.Add("FullName", list.FirstName + " " + list.LastName);

                            // Send email to superadmin
                            //string hostName = Dns.GetHostName();
                            //string myIP = Dns.GetHostByName(hostName).AddressList[0].ToString();
                            //CommonFunctions.SendEmail("*****@*****.**", "Superadmin Login Notification", strBody);
                            //return RedirectToRoute("AdminDashboardRoute");
                            return(RedirectToAction("Index", "ManageUser", new { @area = "Admin" }));
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                        return(View(model));
                    }
                }
                else
                {
                    ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                    return(View(model));
                }
            }
            ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
            return(View(model));
        }
Exemple #18
0
        public ActionResult SuperAdminLogin(LoginViewModel model, string returnUrl)
        {
            List <smIndustry> newlist = _manageContentService.GetCategories();

            ViewBag.IndustryName = new SelectList(newlist, "IndustryId", "IndustryName");
            if (ModelState.IsValid)
            {
                // ServiceLayer.Services.ResetPasswordService _ResetPasswordService = new ServiceLayer.Services.ResetPasswordService();
                List <Core.Domain.Users> list = _userService.GetUsersByEmail(model.UserName.ToString());
                if (list.Count > 0)
                {
                    Core.Domain.Users _objuser = list.FirstOrDefault();
                    var pass = smartData.Common.CommonFunction.Encrypt(model.Password);
                    Core.Domain.Users user = null;
                    if (_objuser.IsSuperAdmin == true && model.IndustryId == 0)
                    {
                        user = _userService.AuthenticateSuperAdmin(model.UserName, pass);
                    }

                    else
                    {
                        user = _userService.AuthenticateUser(model.UserName, model.IndustryId, pass);
                    }

                    if (user != null)
                    {
                        int    cID     = WebSecurity.GetUserId(model.UserName);
                        string TokenID = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                        Session["TokenID"] = TokenID;
                        if (_objuser.UserTypeId == 1)
                        {
                            ViewBag.ErrMessage = true;
                            return(View());
                        }
                        else
                        {
                            if (Session["TokenID"].ToString() == "")
                            {
                                TokenID            = _screenPermissionService.GetAuthorizeToken(Convert.ToInt32(cID));
                                Session["TokenID"] = TokenID;
                            }
                            if (model.RememberMe)
                            {
                                CreateAuthenticateFormsTicket(model);
                            }
                            CreateAuthenticateFormsTicket(model);
                            if (returnUrl != null && returnUrl != "/")
                            {
                                return(Redirect(returnUrl));
                            }
                            var ProfileImage = _objuser.Photo == null ? false : true;
                            //Fill session accordin to the user type.
                            SessionManager.FillAdminSession(_objuser.UserId, _objuser.FirstName, _objuser.LastName, _objuser.Email, Convert.ToInt32(_objuser.UserTypeId), ProfileImage, _objuser.IsSuperAdmin, model.IndustryId);
                            GlobalVar.Insudtry = smartData.Common.SessionManager.LoggedInUser.IndustryId;
                            GlobalVar.userType = smartData.Common.SessionManager.LoggedInUser.UserType;
                            ViewData.Add("FullName", list[0].FirstName + " " + list[0].LastName);

                            // Send email to superadmin
                            string hostName = Dns.GetHostName();
                            string myIP     = Dns.GetHostByName(hostName).AddressList[0].ToString();
                            #region strbody for email
                            string strBody = string.Empty;
                            strBody = "<body marginwidth='0' marginheight='0' offset='0' topmargin='0' leftmargin='0'>" +
                                      "<center>" +
                                      "<table id='bodyTable' width='100%' cellspacing='0' cellpadding='0' border='0' align='center' height='100%' style='background-color: #dee0e2;'>" +
                                      "<tbody>" +
                                      "<tr>" +
                                      "<td id='bodyCell' valign='top' align='center' style='border-top: 4px solid #bbbbbb; padding: 20px;'>" +
                                      "<table cellspacing='0' cellpadding='0' border='0' style='border: 1px solid #bbbbbb; width: 600px;'>" +
                                      "<tbody>" +
                                      // GetHeaderString() +
                                      "<tr>" +
                                      "<td valign='top' align='center'>" +
                                      "<table id='templateBody' width='100%' cellspacing='0' cellpadding='0' border='0' style='background-color: #f4f4f4; border-bottom: 1px solid #cccccc;  border-top: 1px solid #ffffff;'>" +
                                      "<tbody>" +
                                      "<tr>" +
                                      "<td class='bodyContent' valign='top' mc:edit='body_content' style='color: #505050;font-family: Helvetica;font-size: 16px;line-height: 150%; padding: 20px; text-align: left;'>" +
                                      "<h1 style='color: #202020 !important; font-size: 26px; line-height: 100%; margin: 0 0 10px; '>Hi " + list[0].FirstName + ",</h1>" +
                                      "<br />" +
                                      "Someone attempts to login in a superadmin section. " + "<br />" +
                                      "With following Ip address: " + myIP +
                                      "<br>" +
                                      "<br />" +
                                      "Thanks," +
                                      "<br /> <br />" +
                                      "The " + @System.Configuration.ConfigurationManager.AppSettings["ApplicationName"] + " Team" +
                                      " </td>" +
                                      "</tr>" +
                                      "</tbody>" +
                                      "</table>" +
                                      " </td>" +
                                      "</tr>" +
                                      // GetFooterString() +
                                      "</tbody>" +
                                      "</table>" +
                                      "</td>" +
                                      "</tr>" +
                                      "</tbody>" +
                                      "</table>" +
                                      "</center>" +
                                      "</body>";
                            #endregion
                            CommonFunctions.SendEmail("*****@*****.**", "Superadmin Login Notification", strBody);
                            return(RedirectToRoute("AdminDashboardRoute"));
                        }
                    }
                    else
                    {
                        TempData["Message"] = "errorInvalidUser";
                        //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                        return(View(model));
                    }
                }
                else
                {
                    TempData["Message"] = "errorInvalidUser";
                    //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
                    return(View(model));
                }
            }
            TempData["Message"] = "errorInvalidUser";
            //ModelState.AddModelError("", CustomMessages.InvalidUserOrPass);
            return(View(model));
        }
        public int RegisterUser(Core.Domain.Users user)
        {
            if (user == null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            // Check Email exist.
            if (_userRepository.Table.Where(u => u.Email.ToLower().Equals(user.Email) && u.IsDeleted == false).FirstOrDefault() != null)
            {
                throw new Exception("Email already exist.");
            }

            // Check Organization Exist
            if ((user.OrganizationId <= 0 || user.OrganizationId == null) && user.Organization != null && !String.IsNullOrEmpty(user.Organization.OrganizationName))
            {
                var organization = _organizationRepository.Table.Where(o => o.OrganizationName.Equals(user.Organization.OrganizationName)).FirstOrDefault();
                if (organization == null)
                {
                    user.Organization.CreatedDate = DateTime.Now;
                    _organizationRepository.Insert(user.Organization);
                    user.OrganizationId = user.Organization.Id;
                    RegisterInitialDataForOrganization(user.OrganizationId.Value);
                }
                else
                {
                    user.Organization   = organization;
                    user.OrganizationId = organization.Id;
                }
                user.IsOrganizationAdmin = true;
                user.IsActive            = true;
            }
            else if (user.OrganizationId > 0)
            {
                user.IsActive = false;
            }
            else if (user.OrganizationId == 0 || user.OrganizationId == null)
            {
                user.IsActive = true;
            }
            user.MyCode      = GetRefferalCode();
            user.IsDeleted   = false;
            user.CreatedDate = DateTime.Now;
            this._userRepository.Insert(user);

            if (!String.IsNullOrEmpty(user.RefferalCode))
            {
                var refferalUser = this._userRepository.Table.Where(u => u.MyCode.Equals(user.RefferalCode)).FirstOrDefault();
                if (refferalUser != null)
                {
                    var userRewardPoint = this._userRewardPointRepository.Table.Where(r => r.UserId == refferalUser.Id).FirstOrDefault();
                    if (userRewardPoint != null)
                    {
                        // Update reward points of user who shared referral code
                        userRewardPoint.RewardPoints += 100;
                        this._userRewardPointRepository.Update(userRewardPoint);
                    }
                    else
                    {
                        // Add Reward point for existing user who shared refferral code.
                        userRewardPoint              = new UserRewardPoint();
                        userRewardPoint.UserId       = refferalUser.Id;
                        userRewardPoint.RewardPoints = 100;
                        this._userRewardPointRepository.Insert(userRewardPoint);
                    }

                    // Add Reward point for new user who used refferral code.
                    userRewardPoint              = new UserRewardPoint();
                    userRewardPoint.UserId       = user.Id;
                    userRewardPoint.RewardPoints = 100;
                    this._userRewardPointRepository.Insert(userRewardPoint);
                }
            }

            return(user.Id);
        }
Exemple #20
0
 public ActionResult GetUserById(int id)
 {
     Core.Domain.Users Users = _userService.GetUserById(id);
     return(Json(Users, JsonRequestBehavior.AllowGet));
 }