Exemple #1
0
        public ActionResult Edit(ExpertsObjects objE)
        {
            var b = new ExpertsBCL().Update(objE);

            if (b)
            {
                var acc = new AccountBCL().GetByUserId(objE.ExpertId);
                if (acc != null)
                {
                    acc.FullName    = objE.FullName;
                    acc.Username    = objE.Email;
                    acc.Email       = objE.Email;
                    acc.Phone       = objE.Mobile;
                    acc.Description = objE.Description;
                    acc.Isdeleted   = objE.Status;
                    new AccountBCL().Update(acc);
                }
                return(RedirectToAction("Index", "Expert"));
            }
            else
            {
                ModelState.AddModelError("", "them moi that bai");
            }
            return(View());
        }
Exemple #2
0
 public ActionResult Login(AccountObject obj)
 {
     if (ModelState.IsValid)
     {
         var result = new AccountBCL().Login(obj.UserName, obj.Password);
         if (result == 1)
         {
             AccountObject objAccount = new AccountBCL().CheckLogin(obj.UserName, obj.Password);
             Session.Add(Comomconstants.USER_SESSION, objAccount);
             return(RedirectToAction("Index", "Home"));
         }
         else if (result == 0)
         {
             ModelState.AddModelError("", "Tài khoản không tồn tại");
         }
         else if (result == -1)
         {
             ModelState.AddModelError("", "Tài khoản đang bị khóa");
         }
         else if (result == -2)
         {
             ModelState.AddModelError("", "Mật khẩu không tồn tại");
         }
         else if (result == 2)
         {
             ModelState.AddModelError("", "Tài khoản bạn đã bị xóa");
         }
     }
     return(View("Index"));
 }
Exemple #3
0
 public ActionResult Create(AccountObject obj, HttpPostedFileBase Avatar)
 {
     if (ModelState.IsValid)
     {
         if (Avatar != null)
         {
             string name = System.IO.Path.GetFileName(Avatar.FileName);
             string path = System.IO.Path.Combine(Server.MapPath("~/Areas/Admin/Content/assets/ImageAccount/images"), name);
             Avatar.SaveAs(path);
             obj.Avatar = Avatar.FileName;
         }
         obj.AccountID = Guid.NewGuid();
         obj.JoinDay   = DateTime.Now;
         obj.IsDeleted = false;
         var ob = new AccountBCL().Insert(obj);
         if (ob == true)
         {
             return(RedirectToAction("Index", "Account"));
         }
         else
         {
             ModelState.AddModelError("", "Thêm thất bại");
         }
     }
     return(View("index"));
 }
        public ActionResult Edit(Guid id)
        {
            var acc = new AccountBCL().GetByUserId(id);

            ViewBag.ItMe = acc != null && new Models.Login().GetAccount().UserId == acc.UserId;
            return(View(new AccountBCL().GetByUserId(id)));
        }
        public ActionResult Create_main(NotificationsObjects obj)
        {
            obj.notificationsID = Guid.NewGuid();
            obj.StartDate       = DateTime.Now;
            obj.Isdeleted       = false;
            obj.status          = false;
            var accout = new Models.Login().GetAccount();

            obj.UserId = accout.UserId;
            string        title   = "Thông báo";
            string        content = obj.Content;
            AccountObject obj1    = new AccountBCL().GetByUserId(obj.UserId2.GetValueOrDefault());
            string        email   = obj1.Email;
            //string email = "*****@*****.**";
            string bcc = "[email protected],[email protected],[email protected]";

            new SMTPHelper().sendMail(content, email, bcc, title);

            var b = new NotificationsBCL().INSERT(obj);

            if (b)
            {
                return(RedirectToAction("NotificationIndex", "NotificationsManage"));
            }
            else
            {
                ModelState.AddModelError("", "them moi that bai");
            }
            return(View());
        }
Exemple #6
0
        public ActionResult ConfirmEmail(AccountObject objAccount)
        {
            //objAccount.Gender = Request["Gender"].Equals("male"); // Lấy giới tính string => bool

            // Check email empty string + không trùng trong db
            if (string.IsNullOrEmpty(objAccount.Email) && AccountBCL.CheckEmail(objAccount.Email))
            {
                // Nếu email trống hoặc đã tồn tại, tải lại trang và yêu cầu kiểm tra lại
                ViewBag.ErrorEmail = true; // Mình thích thì mình báo lỗi thôi
                return(View(objAccount));
            }

            // Email đã hợp lệ
            // Cho phép thêm tài khoản vào csdl
            objAccount.AccountID = Guid.NewGuid();
            //objAccount.RoleId = 3; // tk thường
            //objAccount.ModifiedTime = DateTime.Now;
            new AccountBCL().Insert(objAccount);

            // Tạo session
            Session.Add(Comomconstants.USER_SESSION, objAccount);

            // Tải lại trang
            return(RedirectToAction("Index", "Home"));
        }
Exemple #7
0
        public async Task <ActionResult> LoginGoogle(CancellationToken cancellationToken)
        {
            var result = await new AuthorizationCodeMvcApp(this, new AppFlowMetadata()).
                         AuthorizeAsync(cancellationToken);

            if (result.Credential == null)
            {
                return(new RedirectResult(result.RedirectUri));
            }

            var plusService = new PlusService(new BaseClientService.Initializer
            {
                HttpClientInitializer = result.Credential,
                ApplicationName       = "MvcLogin App"
            });

            // Lấy thông tin cơ bản của user
            var me = plusService.People.Get("me").Execute();

            if (me != null)
            {
                // Kiểm tra xem tk đã có trong csdl chưa qua google id
                var objAccountRsChecked = AccountBCL.CheckGoogleId(me.Id);
                if (objAccountRsChecked != null)
                {
                    // Đã có trong csdl rồi
                    // Tạo session đăng nhập thành công
                    Session.Add(Comomconstants.USER_SESSION, objAccountRsChecked);

                    // Tải lại trang
                    return(RedirectToAction("Index", "Home"));
                }
                // Nếu chưa có tk, insert vào csdl đăng ký. Sau đó tạo session đăng nhập thành công
                // Đóng gói đối tượng
                var objAccount = new AccountObject()
                {
                    Email    = me.Emails.ElementAt(0).Value,
                    FullName = me.Name.GivenName + " " + me.Name.FamilyName,
                    ID_Gmail = me.Id,
                    Avatar   = me.Image.Url
                };
                //string DisplayName = me.DisplayName;
                //string Provider = IdentityProvider.Google;

                // Insert tk xuống csdl
                objAccount.AccountID = Guid.NewGuid();
                //objAccount.RoleId = 3; // tk thường
                //objAccount.ModifiedTime = DateTime.Now;
                new AccountBCL().Insert(objAccount);

                // Tạo session
                Session.Add(Comomconstants.USER_SESSION, objAccount);

                // Tải lại trang
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #8
0
        public ActionResult Create()
        {
            List <FeaIdObject> LisFeat = new FeaIdBCL().GetAll();

            ViewBag.ListFeat = LisFeat;

            List <AccountObject> lisUser = new AccountBCL().GetAll();

            ViewBag.ListUser = lisUser;
            return(View());
        }
Exemple #9
0
        public JsonResult check(string username)
        {
            var result = new AccountBCL().CheckUsername(username);

            if (result != null)
            {
                return(Json(new string[] { "1", "Tài khoản " + result.FullName + " đã tồn tại" }));
            }
            else
            {
                return(Json(new string[] { "0", "Tài khoản " + username + " có thể sử dụng" }));
            }
        }
Exemple #10
0
        public ActionResult LoginClient(Login_Object loginObject)
        {
            if (ModelState.IsValid)
            {
                var result = new AccountBCL().Login(loginObject.Username, loginObject.Password);

                switch (result)
                {
                case 1:
                {
                    var accountLogin = new AccountBCL().CheckLogin(loginObject.Username, loginObject.Password);
                    // session
                    Session.Add(Comomconstants.USER_SESSION, accountLogin);
                    // cookie
                    FormsAuthentication.SetAuthCookie(loginObject.Username, loginObject.RememberMe);
                    return(RedirectToAction("Index", "Home"));
                }

                case 0:
                {
                    ModelState.AddModelError("", "Tài khoản không tồn tại");

                    break;
                }

                case -2:
                {
                    ModelState.AddModelError("", "Mật khẩu không chính xác");
                    break;
                }


                case -1:
                {
                    ModelState.AddModelError("", "Tài khoản này đang bị khóa");
                    break;
                }


                case 2:
                {
                    ModelState.AddModelError("", "Tài khoản này đã bị xóa");
                    break;
                }
                }
            }
            return(View(loginObject));
        }
Exemple #11
0
        // GET: Admin/Account
        public ActionResult Index()
        {
            AccountObject objAcc = (AccountObject)Session[Commom.Comomconstants.USER_SESSION];

            if (objAcc == null)
            {
                return(RedirectToAction("Login"));
            }
            else if (objAcc.RoleID == 0)
            {
                return(View(new AccountBCL().GetAll()));
            }
            var lisAccount = new AccountBCL().GetAll().Where(x => x.RoleID != 0 && x.RoleID != 1 || x.AccountID == objAcc.AccountID);

            return(View(lisAccount));
        }
        Ordernumber GetOderNumber(Guid AccountID)
        {
            AccountObject objAccout = new AccountBCL().GetByUserId(AccountID);
            var           objrole   = new RoleBCL().GetByRoleId((Guid)objAccout.RoleId);

            switch (objrole.RName)
            {
            case "SuperAdmin":
                return(Ordernumber.SuperAmin);

            case "Admin":
                return(Ordernumber.Admin);

            case "TuVanVien":
                return(Ordernumber.Moderator);

            default:
                return(Ordernumber.Member);
            }
        }
Exemple #13
0
        public ActionResult Update(AccountObject obj, HttpPostedFileBase Avatar, Guid ID)
        {
            var List = new AccountBCL().GetByID(ID);

            if (Avatar != null)
            {
                string name = System.IO.Path.GetFileName(Avatar.FileName);
                string path = System.IO.Path.Combine(Server.MapPath("~/Areas/Admin/Content/assets/ImageAccount/images"), name);
                Avatar.SaveAs(path);
                obj.Avatar = Avatar.FileName;
                new AccountBCL().Update(obj);
                return(RedirectToAction("Index", "Account"));
            }
            else
            {
                obj.Avatar = List.Avatar;
                new AccountBCL().Update(obj);
                return(RedirectToAction("Index"));
            }
        }
Exemple #14
0
        Ordernumber GetOderNumber(Guid AccountID)
        {
            AccountObject objAccout = new AccountBCL().GetByID(AccountID);
            var           objrole   = new RoleBCL().GetById(objAccout.RoleID);

            switch (objrole.RoleName)
            {
            case "SuperAmin":
                return(Ordernumber.SuperAmin);

            case "Admin":
                return(Ordernumber.Admin);

            case "Moderator":
                return(Ordernumber.Moderator);

            default:
                return(Ordernumber.Member);
            }
        }
Exemple #15
0
        public bool CheckLogin(UserLogin ob)
        {
            Logout();
            var acc = new AccountBCL().CheckLogin(new AccountObject()
            {
                Username = ob.Username, PassWord = ob.Password
            });

            if (acc != null)
            {
                if (ob.Remember)
                {
                    SetCookie(new UserLogin()
                    {
                        Username = ob.Username,
                        Password = MaHoa(MaHoa(ob.Password))
                    });
                }
                HttpContext.Current.Session[LOGIN] = new Models.Permission(acc);
                return(true);
            }
            return(false);
        }
Exemple #16
0
        public ActionResult Create(ExpertsObjects objE)
        {
            objE.ExpertId = Guid.NewGuid();
            objE.Deleted  = false;
            objE.Status   = false;
            var lisAcc = new AccountBCL().GetAll().Any(x => x.Username == objE.Email);

            if (lisAcc == false)
            {
                var b = new ExpertsBCL().Insert(objE);
                if (b)
                {
                    AccountObject acc = new AccountObject();
                    acc.UserId      = objE.ExpertId;
                    acc.FullName    = objE.FullName;
                    acc.PassWord    = "******";
                    acc.Username    = objE.Email;
                    acc.Email       = objE.Email;
                    acc.Phone       = objE.Mobile;
                    acc.Description = objE.Description;
                    acc.Isdeleted   = objE.Deleted;
                    acc.RoleId      = Guid.Parse("adae8847-5b4d-43fc-a761-038b315d7651");
                    new AccountBCL().Insert(acc);
                    return(RedirectToAction("Index", "Expert"));
                }
                else
                {
                    ModelState.AddModelError("", "them moi that bai");
                }
            }
            else
            {
                ModelState.AddModelError("", "Tài khoản đã có người sử dụng");
            }
            return(View());
        }
Exemple #17
0
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = ConfigurationManager.AppSettings["FacebookAppId"],
                client_secret = ConfigurationManager.AppSettings["FacebookAppSecret"],
                redirect_uri  = RedirectUri.AbsoluteUri,
                code
            });

            var accessToken = result.access_token;

            if (!string.IsNullOrEmpty(accessToken))
            {
                fb.AccessToken = accessToken;
                // Get the user's information, like email, first name, middle name etc
                dynamic me = fb.Get("me?fields=id,name,gender,picture,email,birthday,locale");

                // Kiểm tra xem tk đã có trong csdl chưa qua facebook id
                var objAccountRsChecked = AccountBCL.CheckFacebookId(me.id);
                if (objAccountRsChecked != null)
                {
                    // Đã có trong csdl rồi
                    // Tạo session đăng nhập thành công
                    Session.Add(Comomconstants.USER_SESSION, objAccountRsChecked);

                    // Tải lại trang
                    return(RedirectToAction("Index", "Home"));
                }
                // Nếu chưa có tk, insert vào csdl đăng ký. Sau đó tạo session đăng nhập thành công
                // Đóng gói đối tượng
                var birthDay   = me.birthday;
                var objAccount = new AccountObject()
                {
                    Email       = me.email,
                    FullName    = me.name,
                    ID_Facebook = me.id,
                    Avatar      = me.picture.data.url
                };
                if (!string.IsNullOrEmpty(birthDay))
                {
                    objAccount.BirthDay = DateTime.ParseExact(birthDay, "MM/dd/yyyy", CultureInfo.InvariantCulture);
                }


                // Nếu ko lấy đc mail thì dãn đến trang cho phép nhập mail
                if (string.IsNullOrEmpty(objAccount.Email))
                {
                    ViewBag.ErrorEmail = false; // Tạm thời chưa có lỗi ở email
                    return(View("ConfirmEmail", objAccount));
                }
                // Insert tk xuống csdl
                objAccount.AccountID = Guid.NewGuid();
                // objAccount.RoleId = 100; // tk thường

                new AccountBCL().Insert(objAccount);

                // Tạo session
                Session.Add(Comomconstants.USER_SESSION, objAccount);

                // Tải lại trang
                return(RedirectToAction("Index", "Home"));
            }
            return(RedirectToAction("Index", "Home"));
        }
Exemple #18
0
        public JsonResult Delete(System.Guid id)
        {
            var result = new AccountBCL().Delete(id);

            return(Json(result ? new { rs = true } : new { rs = false }));
        }