Ejemplo n.º 1
0
        /// <summary>
        /// 前端获取用户的微信信息,再发送到后端接口
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public ResponseEntity <string> RegisterUser(User userDTO)
        {
            ResponseEntity <string> response = new ResponseEntity <string>();

            var dao  = new UserDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            var user = dao.GetUser(userDTO.openId);

            if (user == null || user.id == 0)
            {
                bool success = dao.AddUser(userDTO);

                if (success)
                {
                    response = new ResponseEntity <string>(true, "添加用户成功", "添加用户成功");
                }
                else
                {
                    response = new ResponseEntity <string>(true, "添加用户失败", "添加用户失败");
                }
            }
            else
            {
                response = new ResponseEntity <string>(true, "用户已存在", "用户已存在");
            }

            return(response);
        }
Ejemplo n.º 2
0
 public ActionResult AddUser(EditUserModel user)
 {
     if (ModelState.IsValid)
     {
         if (user.Password == user.RePassword)
         {
             user _user = new user()
             {
                 email      = user.Email,
                 full_name  = user.FullName,
                 password   = user.Password,
                 RoleID     = 2,
                 username   = user.UserName,
                 created_at = DateTime.Now
             };
             var dao = new UserDao();
             dao.AddUser(_user);
         }
         else
         {
             ModelState.AddModelError("", "Mật khẩu không khớp");
         }
     }
     else
     {
         ModelState.AddModelError("", "dang ky khong dung");
     }
     return(View());
 }
        public HttpResponseMessage AddStudent([FromBody] JObject studentInfo)
        {
            try
            {
                var jsonParams = HttpUtil.Deserialize(studentInfo);

                string signature = HttpUtil.GetAuthorization(Request);
                if (signature == null || !redis.IsSet(signature))
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                bool login = redis.IsSet(signature);
                if (!login)
                {
                    return(new Response(2001, "未登录账户").Convert());
                }
                string id   = redis.Get <string>(signature);
                User   user = UserDao.GetUserById(id);


                if (user.role != 4 && user.role != 3)
                {
                    return(new Response(2002).Convert());
                }

                User toAdd = new User();
                QuickCopy.Copy(studentInfo, ref toAdd);
                toAdd.name      = toAdd.name.ToLower();
                toAdd.is_accept = false;
                toAdd.nick_name = toAdd.name;
                toAdd.role      = 1;
                toAdd.passwd    = ConfigurationManager.AppSettings["DefaultUserPasswd"];


                if (user.role == 3 && toAdd.department_id != null && user.department_id != toAdd.department_id)
                {
                    return(new Response(2002, "不能添加其他系的学生").Convert());
                }
                if (user.role == 4 && toAdd.department_id == null)
                {
                    return(new Response(3001, "院系不能为空").Convert());
                }
                if (user.role == 3)
                {
                    toAdd.department_id = user.department_id;
                }

                List <User> users = new List <User>();
                users.Add(toAdd);
                UserDao.AddUser(users);
                return(new Response(1001, "添加成功").Convert());
            }
            catch (Exception e)
            {
                ErrorLogUtil.WriteLogToFile(e, Request);
                return(Response.Error());
            }
        }
        public IEnumerable <User.AddUserR> InsertUser()
        {
            User user = new User();

            user.Name = "wuhaha";
            user.Pwd  = "123456";
            User.AddUserR addUserR = UserDao.AddUser(user);
            yield return(addUserR);
        }
Ejemplo n.º 5
0
        public bool AddUser(UserDto ud)
        {
            um.UserName = ud.UserName;
            um.Password = ud.Password;
            um.Name     = ud.Name;
            um.MobilNo  = ud.MobileNo;
            um.EmailId  = ud.EmailId;

            return(dao.AddUser(um));
        }
Ejemplo n.º 6
0
 public string AddUserProfile()
 {
     try
     {
         userDao.AddUser(ID, username, password, firstName, lastName, email);
         LoginUser(username, password);
         return("Your profile has been sucessfully updated");
     }
     catch (Exception ex)
     {
         return("Username is alredy registered, try another");
     }
 }
Ejemplo n.º 7
0
        public string AddUser(User user)
        {
            var number = _userDao.AddUser(user);

            if (number)
            {
                return($"Success");
            }
            else
            {
                return($"Error");
            }
        }
Ejemplo n.º 8
0
        public string Register(string data, Client client, Server server)
        {
            string[] strs     = data.Split(',');
            string   username = strs[0];
            string   password = strs[1];
            bool     res      = userDao.GetUserByUsername(client.MySqlConnection, username);

            if (res) //找到了要注册的用户名,注册失败
            {
                return(((int)ReturnCode.Fail).ToString());
            }
            userDao.AddUser(client.MySqlConnection, username, password);
            return(((int)ReturnCode.Success).ToString());
        }
Ejemplo n.º 9
0
 public User AddUser(string name, string password)
 {
     if (userDao.GetUser(name) != null)
     {
         return(null);
     }
     else
     {
         User user = new User();
         user.Name     = name;
         user.Password = password;
         userDao.AddUser(user);
         return(user);
     }
 }
Ejemplo n.º 10
0
 public ActionResult AddUser(user user)
 {
     user.RoleID = 2;
     if (ModelState.IsValid)
     {
         user.created_at = DateTime.Now;
         var dao = new UserDao();
         dao.AddUser(user);
     }
     else
     {
         ModelState.AddModelError("", "dang ky khong dung");
     }
     return(RedirectToAction("Index", "Home"));
 }
Ejemplo n.º 11
0
    protected void btn_resister_Click(object sender, EventArgs e)
    {
        String username = tb_username.Text.ToString();
        String password = tb_pwd.Text.ToString();

        UserDao udao = new UserDao();


        String sql = "insert into user (username,psw) values ('" + username + "','" + password + "')";



        udao.AddUser(sql);


        Response.Redirect("index.aspx");
    }
Ejemplo n.º 12
0
        public Boolean AddUser(User user)
        {
            if (user != null)
            {
                user.Rid = 1;

                int res = _userDao.AddUser(user);
                if (res != 1)
                {
                    return(false);
                }

                return(true);
            }

            return(false);
        }
Ejemplo n.º 13
0
        public async Task <Result> AddUser(In <AddUserIn> inData)
        {
            Result result = await VerifyAddUser(inData.data);

            if (!result.result)
            {
                return(result);
            }
            DBHelper db = new DBHelper();

            try
            {
                db.BeginTransaction();
                int position_id   = int.Parse(inData.data.position_id);
                int department_id = await PositionDao.GetDepartmentId(db, position_id);

                int user_id = await UserDao.AddUser(db, inData.data, department_id);

                if (user_id <= 0)
                {
                    db.Rollback();
                    result.msg = "用户添加失败[1]";
                    return(result);
                }
                bool update_user_pwd_flag = await UserDao.UpdatePassword(db, user_id, inData.data.password);

                if (!update_user_pwd_flag)
                {
                    db.Rollback();
                    result.msg = "用户添加失败[2]";
                    return(result);
                }

                db.Commit();
                result.msg    = "添加成功";
                result.result = true;
            }
            catch (Exception e)
            {
                db.Rollback();
                result.msg = "用户添加失败[3]";
            }
            return(result);
        }
Ejemplo n.º 14
0
        public ResponseEntity <string> AddUser(User userDTO)
        {
            userDTO.openId = Guid.NewGuid().ToString();
            //userDTO.headpic = ConfigurationManager.AppSettings["UploadUrl"] + userDTO.headpic;

            if (!string.IsNullOrEmpty(userDTO.headpic) && userDTO.headpic.IndexOf("base64,") > -1)
            {
                try
                {
                    var    img      = Utils.GetImageFromBase64(userDTO.headpic.Substring(userDTO.headpic.IndexOf("base64,") + 7));
                    string fileName = DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".jpg";
                    string fullPath = ConfigurationManager.AppSettings["UploadFolderPath"] + fileName;
                    img.Save(fullPath);

                    userDTO.headpic = ConfigurationManager.AppSettings["UploadUrl"] + fileName;
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message);
                }
            }

            ResponseEntity <string> response = new ResponseEntity <string>();

            var  dao     = new UserDao(ConfigurationManager.AppSettings["mysqlConnStr"]);
            bool success = dao.AddUser(userDTO);

            if (success)
            {
                response = new ResponseEntity <string>(true, "添加用户成功", "添加用户成功");
            }
            else
            {
                response = new ResponseEntity <string>(true, "添加用户失败", "添加用户失败");
            }

            return(response);
        }
Ejemplo n.º 15
0
 public void RegUser(User uModel)
 {
     userDao.AddUser(uModel);
 }
Ejemplo n.º 16
0
 public static bool AddUser(User entity)
 {
     return(UserDao.AddUser(entity));
 }
Ejemplo n.º 17
0
 public static User SignUp(string nickname, string password)
 {
     UserDao.AddUser(nickname, MD5_(password));
     return(UserDao.CheckPassword(nickname, MD5_(password)));
 }
        /// <summary>
        /// 工具函数
        /// </summary>
        /// <param name="admin"></param>
        /// <param name="file"></param>
        /// <param name="role"></param>
        /// <returns></returns>
        public int batchCreateUsers(User admin, HttpPostedFileBase file, int role)
        {
            var severPath = System.Web.Hosting.HostingEnvironment.MapPath("/ExcelFiles/");

            if (!Directory.Exists(severPath))
            {
                Directory.CreateDirectory(severPath);
            }
            var       savePath = Path.Combine(severPath, file.FileName);
            User      user     = null;
            Workbook  workbook = new Workbook();
            Worksheet sheet    = null;
            string    s        = admin.id;

            if (string.Empty.Equals(file.FileName) || (".xls" != Path.GetExtension(file.FileName) && ".xlsx" != Path.GetExtension(file.FileName)))
            {
                return(4);
            }

            file.SaveAs(savePath);
            workbook.LoadFromFile(savePath);
            sheet = workbook.Worksheets[0];
            List <User> userList = new List <User>();
            int         row      = sheet.Rows.Length;    //获取不为空的行数
            int         col      = sheet.Columns.Length; //获取不为空的列数
            int         i;
            string      tempId;
            string      tempName;
            string      tempEmail;
            string      tempDepartment;
            int         idcol         = -11;
            int         namecol       = -11;
            int         emailcol      = -11;
            int         idrow         = -11;
            int         departmentcol = -11;

            CellRange[] cellrange   = sheet.Cells;
            int         rangelength = cellrange.Length;

            for (i = 0; i < row; i++)
            {
                for (int j = 0; j < col; j++)
                {
                    tempId = cellrange[i * col + j].Value;
                    if (tempId.Equals("学号") || tempId.Equals("工号"))
                    {
                        idcol = j;
                        idrow = i + 1;
                    }
                    if (tempId.Equals("姓名"))
                    {
                        namecol = j;
                    }

                    if (tempId.Equals("Email") || tempId.Equals("邮箱"))
                    {
                        emailcol = j;
                    }
                    if (tempId.Equals("所在院系"))
                    {
                        departmentcol = j;
                    }
                }
                if (idcol >= 0 && namecol >= 0)
                {
                    break;
                }
            }

            if (idcol < 0 || namecol < 0)
            {
                return(1);
            }
            if (departmentcol < 0 && admin.role == 4)
            {
                return(2);
            }
            if (departmentcol >= 0 && admin.role == 3)
            {
                for (i = idrow; i < row; i++)
                {
                    tempDepartment = cellrange[i * col + departmentcol].Value;
                    if (tempDepartment != null && tempDepartment != "" && tempDepartment != admin.department_id)
                    {
                        return(3);
                    }
                }
            }
            if (role == 3 && admin.role == 3)
            {
                return(5);
            }

            string departmentId;

            if (admin.role == 3)
            {
                departmentId = admin.department_id;
            }
            else
            {
                departmentId = cellrange[idrow * col + departmentcol].Value.Split(' ')[0];
            }

            string defaultPasswd = ConfigurationManager.AppSettings["DefaultUserPasswd"];

            for (i = idrow; i < row; i++)
            {
                tempId    = cellrange[i * col + idcol].Value;
                tempName  = cellrange[i * col + namecol].Value;
                tempEmail = cellrange[i * col + emailcol].Value;
                if (tempName != "")
                {
                    user               = new User();
                    user.id            = tempId;
                    user.name          = tempName.ToLower();
                    user.nick_name     = null;
                    user.email         = tempEmail;
                    user.passwd        = defaultPasswd;
                    user.department_id = departmentId;
                    user.role          = role;
                    user.is_accept     = false;

                    userList.Add(user);
                }
            }

            UserDao.AddUser(userList);
            return(0);
        }
Ejemplo n.º 19
0
 public bool Register(UserEntity user)
 {
     return(_userDao.AddUser(user));
 }
Ejemplo n.º 20
0
 public void add(string name, string pawd)
 {
     dao.AddUser(name, pawd);
 }
Ejemplo n.º 21
0
 public bool Create(User user)
 {
     return(Dao.AddUser(user));
 }