public ActionResult CreateUser(CreateUserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "password and Confirm password doesnot match");
                return(View(model));
            }

            UserMaster user = UserMaster.GetUserByEmail(model.EmailAddress, con);

            if (user != null)
            {
                ModelState.AddModelError("", "Email already Registered");
                return(View(model));
            }

            string strp = UserMaster.EncryptString(model.Password);

            UserMaster new_user = new UserMaster();

            new_user.cid             = Convert.ToInt32(Session["cid"]);
            new_user.email           = model.EmailAddress;
            new_user.display_name    = model.DisplayName;
            new_user.hashed_password = strp;
            new_user.mobile_number   = model.Mobile;
            new_user.created_by_uid  = Convert.ToInt32(Session["uid"]);

            int i = UserMaster.CreateUser(new_user, con);

            if (i > 0)
            {
                user = UserMaster.GetUserByEmail(model.EmailAddress, con);
                CommonStuff.SendEmail(user.email, "Welcome to DotNetIsEasy.com", CommonStuff.getEmailVerificationBody(user.email, user.emailvalidationToken));

                //user = UserMaster.Login(model.EmailAddress, model.Password, con);

                //Session["uid"] = user.uid;
                //Session["DisplayName"] = user.display_name;
                //Session["cid"] = user.cid;
                return(RedirectToAction("Success", "Account"));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult CreateUser(CreateUserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UserMaster user = UserMaster.GetUserByEmail(model.EmailAddress, con);

            if (user != null)
            {
                ModelState.AddModelError("", "Email already Registered");
                return(View(model));
            }

            string strp = UserMaster.EncryptString(model.Password);

            UserMaster new_user = new UserMaster();

            new_user.cid             = Convert.ToInt32(Session["cid"]);
            new_user.email           = model.EmailAddress;
            new_user.display_name    = model.DisplayName;
            new_user.hashed_password = strp;
            new_user.mobile_number   = model.Mobile;
            new_user.created_by_uid  = Convert.ToInt32(Session["uid"]);

            int i = UserMaster.CreateUser(new_user);

            if (i > 0)
            {
                return(RedirectToAction("Dashboard", "Home"));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult FacebookCallback(string code)
        {
            var     fb     = new FacebookClient();
            dynamic result = fb.Post("oauth/access_token", new
            {
                client_id     = _app_id,
                client_secret = _client_sec,
                redirect_uri  = RedirectUri.AbsoluteUri,
                code          = code
            });

            var accessToken = result.access_token;

            // Store the access token in the session for farther use
            Session["AccessToken"] = accessToken;

            // update the facebook client with the access token so
            // we can make requests on behalf of the user
            fb.AccessToken = accessToken;

            // Get the user's information, like email, first name, middle name etc
            dynamic me          = fb.Get("me?fields=email,first_name,middle_name,last_name,id,name,name_format,picture");
            string  email       = me.email;
            string  firstname   = me.first_name;
            string  middlename  = me.middle_name;
            string  lastname    = me.last_name;
            string  name        = me.name;
            string  name_format = me.name_format;
            string  fb_id       = me.id;
            dynamic pic         = me.picture;

            //string picture = me.picture;

            // Set the auth cookie
            //FormsAuthentication.SetAuthCookie(email, false);

            UserMaster user = new UserMaster();

            string pict = pic[0].url;

            user = UserMaster.GetUserByFacebookId(me.id, con);
            if (user == null)
            {
                user                 = new UserMaster();
                user.email           = (string.IsNullOrEmpty(email) ? me.id : email);
                user.display_name    = firstname + " " + lastname;
                user.FacebookId      = me.id;
                user.created_by_uid  = 1;
                user.hashed_password = "******";
                user.mobile_number   = "N/A";

                user.cid = 1;

                int i = UserMaster.CreateUser(user, con);
                user.uid = i;
            }

            Session["DisplayName"] = user.display_name;

            Session["uid"] = user.uid;


            return(RedirectToAction("Index", "Home"));
        }
Exemple #4
0
        public void CreateUser(string argUserName, string argUserShortID, string argPassword, int argDepartID, string argEmail, int argDesignationID, int argLevelID, string argContact, int argCreatedBy)
        {
            ValidationException error = new ValidationException();
            UserMaster          Table = new UserMaster();

            if (Validations.IsEmpty(argUserShortID))
            {
                error.AddError("Enter Short ID");
            }

            if (Validations.IsEmpty(argUserName))
            {
                error.AddError("Enter User Name");
            }

            if (Validations.IsEmpty(argPassword))
            {
                error.AddError("Enter Password");
            }

            if (Validations.IsEmpty(argContact))
            {
                error.AddError("Enter Mobile Number");
            }

            if (Validations.IsEmpty(argEmail))
            {
                error.AddError("Enter Email");
            }

            if (!Validations.IsEmail(argEmail, true).IsValid)
            {
                error.AddError("Enter Valid Email ID");
            }

            //if (!Validations.IsNumber(argContact))
            //    error.AddError("Enter Number only");

            if (!error.isValid)
            {
                throw error;
            }

            DataSet DSUserCheck = Table.CheckshortID(argUserShortID);

            if (DSUserCheck != null && DSUserCheck.Tables.Count > 0)
            {
                if (int.Parse(DSUserCheck.Tables[0].Rows[0]["Cnt"].ToString()) > 0)
                {
                    throw new UserNonAvailabiltyException();
                }
                else
                {
                    Table.Connection.beginTransact();
                }
            }

            try
            {
                Table.CreateUser(argUserName, argUserShortID, argPassword.Encrypt(), argDepartID, argContact, argEmail, argDesignationID, argLevelID, argCreatedBy);
                Table.Connection.commit();
            }
            catch (Exception ex)
            {
                Table.Connection.rollback();
                throw ex;
            }
        }