public bool RegisterUser(UserEnt ent, ref string errorInfo) { _log.Info("Request to create user " + ent.Email); string sql = "select count(*) from user where email='" + ent.Email + "'"; DataSet ds = Query(sql); if (ds == null) throw new Exception("Failed to query user's data"); int cnt = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString()); if (cnt != 0) { errorInfo = "User already registered"; return false; } string curTime = DateTime.UtcNow.ToString("yyyy-MM-ddThh:mm:ssZ"); sql = string.Format("INSERT INTO user (username, email, user_guid, create_time, update_time, password) VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}')" , ent.Username, ent.Email, Util.GetMD5(ent.Email), curTime, curTime, ent.Password); cnt = ExecuteSql(sql); if (cnt == 0) throw new Exception("Failed to update database"); _log.Info("User " + ent.Email + " created successfully"); return true; }
public UserEnt GetUser(string sql, ref string errorInfo) { DataSet ds = Query(sql); if (ds == null) throw new Exception("Failed to query user's data"); if (ds.Tables[0].Rows.Count == 0) { errorInfo = "User not exist"; return null; } UserEnt ent = new UserEnt(); ent.Username = ds.Tables[0].Rows[0]["username"].ToString(); ent.UserGuid = ds.Tables[0].Rows[0]["user_guid"].ToString(); ent.Email = ds.Tables[0].Rows[0]["email"].ToString(); ent.Password = ds.Tables[0].Rows[0]["password"].ToString(); ent.UpdateTime = ds.Tables[0].Rows[0]["create_time"].ToString(); ent.CreateTime = ds.Tables[0].Rows[0]["update_time"].ToString(); return ent; }